3

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 %}
</ul>

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

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, privacy policy and cookie policy

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