2

I guess this isn't possible as it would mean the content is essentially a Global, but I would like to be able use a block from a matrix field from another entry.

At the moment I have a parent page with a block of content, which I would like to replicate on all of it's child pages. I don't want to make the user repeat it on each child page, but I don't want to hardcode it.

1 Answer 1

5

You can query for that parent page's entry model with a new ElementCriteriaModel.

{% set mainEntry = craft.entries.id(100).first() %}

{% if mainEntry %}
    {% set matrixField = mainEntry.matrixFieldHandle %}
    {% set firstContentBlock = matrixField.type('content').first() %}

    {% if firstContentBlock %}
        {{ firstContentBlock.myRichTextFieldHandle }}
    {% endif %}
{% endif %}

Instead of using the entry's ID as the link to that entry, you can also use other parameters to query for the entry model. Here's an example using slug and section:

{% set mainEntry = craft.entries.section('news').slug('main-news').first() %}
1
  • Worked great, thanks! I guess the distinction I had to understand was I'm getting info from the entry, not the field. so you have to return query the model using the slug or ID. Makes sense! Commented Aug 26, 2015 at 15:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.