1

Following this topic, I have an additional question.

The results are not ordered by the order of the Dropdown Options. How can I get this done?

order

Code:

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

{% for position, playersInPosition in playersGrouped %}
    <h2>{{ position }}</h2>
    <ul>
    {% for player in playersInPosition %}
        {% set playerData = craft.entries.section('myPlayersChannel').relatedTo(player).first() %}
        <li>
            {{ playerData.fullName }}
            {{ playerData.age }}
            ...
        </li>
    {% endfor %}
    </ul>
{% endfor %}
1

You could wrap this in another for loop and put a condition on the inner fors,

something like

{% for option in myPositionDropdown %}
  <h2>{{ option.value }}</h2>

  {% for position, playersInPosition in playersGrouped if position == option.value %}    
    <ul>

    {% for player in playersInPosition %}
      {% set playerData = craft.entries.section('myPlayersChannel').relatedTo(player).first() %}
      <li>
        {{ playerData.fullName }}
        {{ playerData.age }}
        ...
      </li>
    {% endfor %}

    </ul>
  {% endfor %}

{% endfor %}

(untested code)

That sort of idea though, loop the dropdown in order and show the grouped results. Heck, you probably don't need to group them at all since you're filtering them out in each loop.

HTH

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.