I came across a specific situation where I needed to list out all the values within a collection of Matrix fields on a single entry page.

More specifically, I had a single entry that needed multiple team groups, each with the name, role, and description of various people. I then wanted to list them all out anywhere on the site (single or entry pages).

Hope this solution helps people out. Feel free to critique.

1 Answer 1

{% cache %}
  {% set entry = craft.entries.slug('team').last() %}
  {% for field in entry.getFieldLayout().getFields() %}
    {% if field.getField().type == "Matrix" %}
      {% set fieldHandle = field.getField().handle %}
      {% set matrixBlocks = entry.__get(fieldHandle).find() %}
      {% for block in matrixBlocks %}
        {{ block.team_name }}
      {% endfor %}
    {% endif %}
  {% endfor %}
{% endcache %}

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.