I have a matrix field with a category field. I need to group these matrix items by category and give them headings which I'll use for tabs.

This is how I'd do it for entries but is it possible for matrix?

<ul class="tabs">
    {% nav category in craft.categories.group('otherAppliances') %}

    {% set itemCount = craft.entries.relatedTo(category).total() %}
        {% if itemCount %}

            <li rel="">{{ category.title }}</li>

        {% endif %}
    {% endnav %}

I think my question may be similar to How to query with relatedTo of a Relationship Field in a Matrix Field block but I can't get my head around it.

Matrix setup:

enter image description here

1 Answer 1


Just answering this for anyone that may come across this in the future as I have...

Could you reuse the group tag?

{% for block in entry.myMatrixField.group(<catgegory here>) %}
{% endfor %}

You have probably resolved it due to the age, but your answer would be helpful.

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.