{# Glossary Category ============= Categories in the glossary style #} {# Get all Keys #} {% set catKeys = {} %} {% set collectedCat = craft.categories.group(data).order('title asc') %} {# Readout all first Letter from the categories #} {% for cats in collectedCat %} {# Get the First Letter compare lower #} {% if cats.title|first|lower matches '/^\\d+$/' %} {% set cats_key = '#' %} {% else %} {% set cats_key = cats.title|first|lower %} {% endif %} {# Compare if first letter is in the Object #} {% if catKeys[cats_key] is not defined %} {# Remove double entries #} {% if cats_key not in catKeys %} {% set catKeys = catKeys|merge({(cats_key):[]})%} {% endif %} {% endif %} {% endfor %}
{% for key in catKeys|keys %} {% if key == '#' %} {# Group all categories starting with a number #} {% set catGroupByLetter = collectedCat.search('title:1* OR title:2* OR title:3* OR title:4* OR title:5* OR title:6* OR title:7* OR title:8* OR title:9* OR title:0*' ).order('title asc').limit(null) %}
{{ key }}
{% else %} {# Group all categories starting with a letter #} {% set catGroupByLetter = collectedCat.search('title:' ~ key ~ '*' ).order('title asc').limit(null) %} {% set catCount = '' %} {% for cat in catGroupByLetter if cat.title|first|lower == key %} {% set catCount = catCount + craft.entries.relatedTo(cat).total() %} {% endfor %} {# List only if active categories in the group #} {% if catCount > 0 %}
{{ key }}
{% endif %} {% endif %} {% endfor %}