A-Z filter menu - limiting output to one when there are multiples I have a A-Z menu to filter entries by their first letter.

   &lt;ul class="directory-letters"&gt;
    &lt;li class="all current" data-filter="all"&gt;ALL&lt;/li&gt;
    {% for entry in craft.entries.section('membershipDirectory').order('title asc') %}
      &lt;li data-filter="letter-{{ entry.companyName|slice(0, 1)|lower|replace("/[^a-z]/", "0-9") }}"&gt;{{ entry.companyName|slice(0, 1) }}&lt;/li&gt;
    {% endfor %}
   &lt;/ul&gt;


Issue I have is if there are 4 entries beginning with 'C' the output will be:

A B C C C C D E F...

Can I limit each letter once so I'll get 1 'C' is there are 1+ entries starting with 'C'?



UPDATE:

I'm now getting the right number of instances created but no text inside my . Likely a rookie error somewhere:

{% set allEntries = 
craft.entries.section('membershipDirectory').order('title asc') %}
{% set allEntriesByFirstCharacter = 
 allEntries|group('companyName|slice(0, 1)|lower|replace("/[^a-z]/", 
 "0-9")' ) %}

 &lt;ul class="directory-letters"&gt;
    &lt;li class="all current" data-filter="all"&gt;ALL&lt;/li&gt;
    {% for allEntries in allEntriesByFirstCharacter %}
       &lt;li data-filter="letter-{{ entry.companyName|slice(0, 1)|lower|replace("/[^a-z]/", "0-9") }}"&gt;{{ entry.companyName|slice(0, 1)|lower|replace("/[^a-z]/", "0-9") }}&lt;/li&gt;
  {% endfor %}
&lt;/ul&gt;
You can use the group filter and create a 2d array with the letter as the first index and the entries as second index. 

{% set allEntriesByFirstCharacter = allEntries|group('companyName|slice(0, 1)|lower|replace("/[^a-z]/", "0-9")' ) %}


The string passed in the filter will get rendered as an object template an equal results will be grouped by the same key.