Is it possible to group by a field within a matrix field. I have a channel of players which holds their details. I have a structure for teams which includes a matrix field for a Player.

The Player matrix has 2 fields:

1 - Position (Drop down with: Goalkeeper, Defender, Midfielder)

2 - Entries field linked to Players Channel.

When accessing the matrix is it possible to Group the blocks by the Position field?

1 Answer 1


You should be able to do this with Craft's handy group filter.

{% set players = entry.myPlayersMatrix %}
{% set playersGrouped = players|group('myPositionDropdown.label') %}

{% for position, playersInPosition in playersGrouped %}
    <h2>{{ position }}</h2>
    {% for player in playersInPosition %}
        {% set playerData = craft.entries.section('myPlayersChannel').relatedTo(player).first() %}
            {{ playerData.fullName }}
            {{ playerData.age }}
    {% endfor %}
{% endfor %}
  • Ah - never realised it was possible with matrix fields as well. Straight forward then - thanks!
    – mmc501
    Apr 10, 2015 at 8:19

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.