0

I'm trying to retrieve matrix content from a an Entry field chooseTemplateExample which has a matrix block component with a Entry field component.

{% for template in entry.chooseTemplateExample %}
  <a href="{{ template.url }}" class="btn btn-primary">View {{ template.title }} example</a><br>

  {% for block in template.component %}

     //Trying to get the matrix content within this "template"
     {% for block in entry.chooseComponentForTemplate %}
      {% for component in block.component %}
        {{ title }}
      {% endfor %}
    {% endfor %}

  {% endfor %}

{% endfor %}

Thank you in advance.

1

When you loop through your matrix, you're missing the s on components. Should be:

{% for block in template.components %}

Each item in that loop will be one of the blocks in the matrix. So then you can call {{ block.component }} directly.

FYI, in your code, it looks like that component field in the matrix block is loopable as well? If you're trying to loop through an entries field, and then loop through a matrix field per entry, and then loop through another field per matrix block, expect some serious performance issues.

Full code reference:

{% for template in entry.chooseTemplateExample %}
  <a href="{{ template.url }}" class="btn btn-primary">View {{ template.title }} example</a><br>

  {% for block in template.components %}
    {% for component in block.component %} {!-- Is this field really loopable? --}
      {{ title }}
    {% endfor %}
  {% endfor %}
{% endfor %}
| improve this answer | |
  • Thanks for the reply Ben. I updated my question as I mistyped. I do have a matrix block called component with an Entry field component. I'm trying to get the title of this Entry field component. – julzmon Apr 4 '16 at 18:52
  • I'm getting the following error "Craft\EntryModel and its behaviors do not have a method or closure named "component"." – julzmon Apr 4 '16 at 18:53
1

OK I finally figured it out. Thanks Ben.

{% for template in entry.chooseTemplateExample %}

  <a href="{{ template.url }}" class="btn btn-primary">View {{ template.title }} example</a><br>

  {% for block in template.chooseComponentForTemplate %}

     {% for component in block.component %}
            {{ component.title }}
     {% endfor %}

  {% endfor %}

{% endfor %}
| improve this answer | |

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.