3

I need to group and order member profiles alphabetically but I can't get it to work. Have a look here: http://ffsd.de.w0129b45.kasserver.com/mitglieder (It's german but you should get the idea :))

In everything I tried either the groups are ordered correctly or the contents (profiles) of the group are… but never both. Here's the relevant code:

{% set allProfiles = craft.entries.section('members').order('profileLastname').limit(null) %}
{% for letter, profiles in allProfiles|group("profileAlphabet") %}
    <ul class="member__index">
        <li class="item letter">
            <span id="{{ letter }}">
                <div class="avatar">
                    <span class="initials letter">{{ letter }}</span>
                </div>
            </span>
        </li>

        {% for profile in profiles %}
            <li class="item">
                <a href="{{ profile.url }}"><h3>{{ profile.title }}</h3></a>
            </li>
        {% endfor %}
    </ul>
{% endfor %}

As you can see, I'd like to order the profiles by the custom field "profileLastname" and the groups by "profileAlphabet".

Any ideas?

5

The probably most easy way to do this is to sort the grouped array by key, which unfortunatelly is only possible with a plugin, as Twig's sort filter only allows to sort by value.

Here I'm using Michael Rog's Supersort, but there are also other plugins that do this.

{% set allProfiles = craft.entries.section('members').order('profileLastname').limit(null) %}
{% set allProfilesGrouped = allProfiles|group("profileAlphabet")|supersort('ksort') %}

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.