Alphabetical index for a list of entries I would like to build an alphabetical list of craft entries, but group them by the initials of one field of each entry. Thus, getting some kind of alphabetical index, like

A 


Apples
Ananas


B


Beer


How do I do that?
First, sort all entries by multiple criteria:

{# get our entries and order by firstname, lastname #}
{% set allEntries = craft.entries.section('entries').orderBy('lastname asc, firstname asc').all() %}


Then use craft's custom "group" filter (lastname[:1] picks the first letter):

{# group them by the first letter of the last name https://docs.craftcms.com/v3/dev/filters.html#group #}
{% set allEntriesByGroup = allEntries | group('lastname[:1]') %}


Then loop through that multidimensional array (firstletter, entriesInGroup) is key -&gt; value in twig:

{% for firstletter, entriesInGroup in allEntriesByGroup %}
    &lt;h3&gt;{{firstletter}}&lt;/h3&gt;
    &lt;ul&gt;
    {% for entry in entriesInGroup %}
       &lt;li&gt;{{entry.lastname}}, {{entry.firstname}}&lt;/li&gt;
    {% endfor %}
    &lt;/ul&gt;
{% endfor %}