2

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') %} 
<ul>
{% for letter, categoriesInGroup in categoriesGroup %}
{{ letter }}
{% for category in categoriesInGroup %}
  <li>{{ category.title }}</li>
{% endfor %}

{% endfor %}
</ul>
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') %} 
<ul>
{% for letter, categoriesInGroup in categoriesGroup %}
{{ letter }}
{% for category in categoriesInGroup %}
  <li>{{ category.title }}</li>
{% endfor %}

{% endfor %}
</ul>

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.