0

I have a structure with 1 main Entry and 3 descendants underneath it but I have trouble accessing the data in matrix fields in the entries. I'm trying to do this all on one page:

{% set tabs = entry.descendants %}
     {% for tab in tabs %}
          {{ tab.title }}
     {% endfor %}
{% endfor %}

I can get as far as the tab title, and it displays fine. But I want to access the matrix fields in the descendants. Here are the blocks in my field with the handle 'tab'.

Blocks

So to summarise, I have a structure:

Structure

and then I want to use all those descendant data all one one page but I'm having trouble accessing it.

1

You would loop through the Matrix field within each tab the same way you’d do it for any other element.

{% set tabs = entry.descendants %}
{% for tab in tabs %}
    {{ tab.title }}
    {% for block in tab.myMatrixFieldHandle %}
        {% if block.type == 'about' %}
            ...
        {% elseif block.type == 'team' %}
            ...
        {% elseif block.type == 'clients' %}
            ...
        {% endif %}
    {% endfor %}
{% endfor %}
1
  • Thanks - my problem was in naming as my matrixFieldHandle was actually called 'tab' - bit of a Herp Derp moment!
    – Ryan
    Oct 26 '14 at 4:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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