<p>Seems I needed to put in the order filter</p>

<pre><code>{% set categories = craft.categories.group('programs').order('title') %}

{% set categoriesGroup = categories|group('title|slice(0, 
1)|replace("/[^a-zA-Z]/", "0-9") | upper') %} 
&lt;ul&gt;
{% for letter, categoriesInGroup in categoriesGroup %}
{{ letter }}
{% for category in categoriesInGroup %}
  &lt;li&gt;{{ category.title }}&lt;/li&gt;
{% endfor %}

{% endfor %}
&lt;/ul&gt;
</code></pre>

CC BY-SA 4.0
2018-05-04T02:21:13.330Z
2018-05-04T02:21:13.330Z
Vin
<p>I have a list of categories that I am listing out, grouping by alphabet.  The issue is the list goes A H B C D E...and so on.  Why would it go in that order?</p>

<pre><code>{% set categories = craft.categories.group('programs') %}

{% set categoriesGroup = categories|group('title|slice(0, 
1)|replace("/[^a-zA-Z]/", "0-9") | upper') %} 
&lt;ul&gt;
{% for letter, categoriesInGroup in categoriesGroup %}
{{ letter }}
{% for category in categoriesInGroup %}
  &lt;li&gt;{{ category.title }}&lt;/li&gt;
{% endfor %}

{% endfor %}
&lt;/ul&gt;
</code></pre>

<craft3><sorting>
Group and Sort Alphabetically
# Group and Sort Alphabetically

(Asked by: username_0 on 2018-05-04)

I have a list of categories that I am listing out, grouping by alphabet.  The issue is the list goes A H B C D E...and so on.  Why would it go in that order?
{% set categories = craft.categories.group('programs') %}

{% set categoriesGroup = categories|group('title|slice(0, 
1)|replace("/[^a-zA-Z]/", "0-9") | upper') %} 

{% for letter, categoriesInGroup in categoriesGroup %}
{{ letter }}
{% for category in categoriesInGroup %}
  {{ category.title }}
{% endfor %}

{% endfor %}

**Tags:** craft3, sorting


---

## 1 answers

### Answer by username_0 on 2018-05-04. Score: 4

Seems I needed to put in the order filter
{% set categories = craft.categories.group('programs').order('title') %}

{% set categoriesGroup = categories|group('title|slice(0, 
1)|replace("/[^a-zA-Z]/", "0-9") | upper') %} 

{% for letter, categoriesInGroup in categoriesGroup %}
{{ letter }}
{% for category in categoriesInGroup %}
  {{ category.title }}
{% endfor %}

{% endfor %}


---

