After copying the "group" docs almost verbatim, I'm trying to sort a list of entries by province and then by city, this what I have:

    {# See Group docs for info: https://docs.craftcms.com/v2/templating/filters.html#group #}
    {% set allShopsEntries = craft.entries.section('shops').order('province').order('city') %}
    {% set shopsEntries = allShopsEntries|group('province.label') %}

    {% for province, shopsInProvince in shopsEntries %}

        <h1 id="{{ province }}">{{ province }}</h1>

    <div class="flex">

        {% for shop in shopsInProvince %}
                    <p>{{ shop.title }}</p>
                    <p>{{ shop.address }}</p>
            {% endfor %}

        {% endfor %}

Now forthe most part it works, however the provinces are not ordered alphebetically, the list returned appears to be in order of ID. How could I fix this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.