Answers.Body: <p>If you need only unique letters, you can build a new array and only merge first letters that are not already in the array like this:</p>
  
  <pre><code>{% set letterArray = [] %}
  
  {% for alpha in craft.entries.section('advertisers').order('title asc') %}
    {% if alpha.title|first not in letterArray %}
      {% set letterArray = letterArray|merge([alpha.title|first]) %}
    {% endif %}
  {% endfor %}
  
  {% for letter in letterArray %}
    &lt;a href="{{ siteUrl }}{{ letter }}"&gt;{{ letter }}&lt;/a&gt;
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-06T20:28:54.000Z
Answers.LastActivityDate: 2017-04-06T20:28:54.000Z
Answers.UserDisplayName: Alex Roper
Answers.Body: <p>Completely untested, but something like this should work:</p>
  
  <pre><code>{% set letterArray = [] %}
  
  {% for alpha in craft.entries.section('advertisers').order('title asc') %}
      {% set letterArray = letterArray|merge([alpha.title|first]) %}
  {% endfor %}
  
  {% for letter in letterArray %}
      &lt;a href="{{ siteUrl }}{{ letter }}"&gt;{{ letter }}&lt;/a&gt;
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-06T01:12:23.277Z
Answers.Text: I am getting this error: "The merge filter only works with arrays or "Traversable", got "string" as second argument."
Answers.UserDisplayName: afc
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-06T02:51:03.340Z
Answers.Text: I did say it wasn't tested... try the updated answer.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-08T01:00:59.150Z
Answers.Text: No error but still returns the same as my original code. The suggestion by Alex worked perfect. I appreciate your assistance!
Answers.UserDisplayName: afc
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-08T03:36:31.107Z
Answers.Text: Foiled by @AlexRoper yet again!
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-03T02:57:08.077Z
Answers.LastActivityDate: 2017-04-06T02:50:46.600Z
Answers.LastEditDate: 2017-04-06T02:50:46.600Z
Answers.UserDisplayName: Brad Bell
Body: <p>I've got a for loop that is returning the first letter of the entry title. I have a number of entries so I almost get a complete alphabet except that there are too many of many letters. I only want one 'a', one 'b', one 'c' and so 
  forth. And no letter if there is no entry to correspond to it.</p>
  
  <pre><code>{% for alpha in craft.entries.section('advertisers').order('title asc') %}
      &lt;a href="{{ siteUrl }}{{ alpha.title|first }}"&gt;{{ alpha.title|first }}&lt;/a&gt;
  {% endfor %}
  </code></pre>
  
  <p>This code returns:
  A A A B B B B B C C E E E E G G H H K M M M M P P R R S S S T T U U U W W
  but I want it to return A B C E G H K M P R S T U W</p>
  
  <p>Are there any solutions to this?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-03-31T23:08:13.653Z
Comments.Text: Correct me if I'm wrong, but the only code relevant to your question is the first for loop, right?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-03-31T23:21:16.817Z
Comments.Text: yup. I removed some code to clean it up. I'm still learning the ways of Stackexchange.
Comments.UserDisplayName: afc
Tags: <forloop>
Title: How do I omit similar content in a for loop based on the first letter in title?
ThreadText: # How do I omit similar content in a for loop based on the first letter in title?
  
  (Asked by: username_0 on 2017-03-31)
  
  I've got a for loop that is returning the first letter of the entry title. I have a number of entries so I almost get a complete alphabet except that there are too many of many letters. I only want one 'a', one 'b', one 'c' and so
  forth. And no letter if there is no entry to correspond to it.
  
  ```
  {% for alpha in craft.entries.section('advertisers').order('title asc') %}
      <a href="{{ siteUrl }}{{ alpha.title|first }}">{{ alpha.title|first }}</a>
  {% endfor %}
  
  ```
  
  This code returns:
  A A A B B B B B C C E E E E G G H H K M M M M P P R R S S S T T U U U W W
  but I want it to return A B C E G H K M P R S T U W
  
  Are there any solutions to this?
  
  **Tags:** forloop
  
  > **Comments:**
  > **username_1**: Correct me if I'm wrong, but the only code relevant to your question is the first for loop, right?  
  > **username_0**: yup. I removed some code to clean it up. I'm still learning the ways of Stackexchange.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2017-04-06. Score: 2 | Accepted answer
  
  If you need only unique letters, you can build a new array and only merge first letters that are not already in the array like this:
  
  ```
  {% set letterArray = [] %}
  
  {% for alpha in craft.entries.section('advertisers').order('title asc') %}
    {% if alpha.title|first not in letterArray %}
      {% set letterArray = letterArray|merge([alpha.title|first]) %}
    {% endif %}
  {% endfor %}
  
  {% for letter in letterArray %}
    <a href="{{ siteUrl }}{{ letter }}">{{ letter }}</a>
  {% endfor %}
  
  ```
  
  
  ---
  
  ### Answer by username_1 on 2017-04-03. Score: 1
  
  Completely untested, but something like this should work:
  
  ```
  {% set letterArray = [] %}
  
  {% for alpha in craft.entries.section('advertisers').order('title asc') %}
      {% set letterArray = letterArray|merge([alpha.title|first]) %}
  {% endfor %}
  
  {% for letter in letterArray %}
      <a href="{{ siteUrl }}{{ letter }}">{{ letter }}</a>
  {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_0**: I am getting this error: "The merge filter only works with arrays or "Traversable", got "string" as second argument."  
  > **username_1**: I did say it wasn't tested... try the updated answer.  
  > **username_0**: No error but still returns the same as my original code. The suggestion by username_2 worked perfect. I appreciate your assistance!  
  > **username_1**: Foiled by @username_2 yet again!  
  
  ---
  
  