<p>Craft has a <a href="http://buildwithcraft.com/docs/templating/filters#group" rel="nofollow"><code>group filter</code></a>, that does just that:</p>

<pre><code>{% for stad, events in craft.entries.section('events') | group('stad') %}
    &lt;option value="{{ stad }}"&gt;{{ stad }}&lt;/option&gt;
{% endfor %}
</code></pre>

CC BY-SA 3.0
2015-02-28T16:35:54.093Z
2015-02-28T16:35:54.093Z
Paul
<p>As you are outputting the options, build an array of <code>stad</code> values and check for duplicates on each loop iteration. If the value does not exist in the array, add it to the array and print out the option. </p>

<pre><code>{% set stad_array = [] %}

{% for entry in craft.entries.section('events') %}
    {% if entry.stad not in stad_array %}
        {% set stad_array = stad_array|merge([entry.stad]) %}
        &lt;option value="{{entry.stad}}" name="{{ entry.stad }}"&gt;{{ entry.stad }}&lt;/option&gt;
    {% endif %}
{% endfor %}
</code></pre>

<p>Hope this helps!</p>

CC BY-SA 3.0
2015-03-01T11:11:45.283Z
Thanks for the reply :) However, the other option is easier
Evin Wijninga
CC BY-SA 3.0
2015-03-01T16:04:08.840Z
Agreed! Glad you found a solution :)
Aaron Berkowitz
CC BY-SA 3.0
2015-02-28T15:27:31.440Z
2015-02-28T15:27:31.440Z
Aaron Berkowitz
<p>For an event page I have the option to filter on cities and countries. Each event has entry fields in which the city and country, of which the values are outputted in a drop down list on the front end.</p>

<p>As some events happen in the same country and city I have multipe values that are the same. Is there any chance to filter these values in Craft and output it only ones?</p>

<pre><code>{% for entry in craft.entries.section('events') %}                      
    &lt;option value="{{entry.stad}}" name="{{ entry.stad }}"&gt;{{ entry.stad }}&lt;/option&gt;
{% endfor %}
</code></pre>

<entry><field><filter>
How to check if entry field value is already outputted, and prevent it again?
# How to check if entry field value is already outputted, and prevent it again?

(Asked by: username_0 on 2015-02-28)

For an event page I have the option to filter on cities and countries. Each event has entry fields in which the city and country, of which the values are outputted in a drop down list on the front end.
As some events happen in the same country and city I have multipe values that are the same. Is there any chance to filter these values in Craft and output it only ones?
{% for entry in craft.entries.section('events') %}                      
    {{ entry.stad }}
{% endfor %}

**Tags:** entry, field, filter


---

## 2 answers

### Answer by username_1 on 2015-02-28. Score: 3 | Accepted answer

Craft has a group filter, that does just that:
{% for stad, events in craft.entries.section('events') | group('stad') %}
    {{ stad }}
{% endfor %}


---

### Answer by username_2 on 2015-02-28. Score: 2

As you are outputting the options, build an array of stad values and check for duplicates on each loop iteration. If the value does not exist in the array, add it to the array and print out the option. 
{% set stad_array = [] %}

{% for entry in craft.entries.section('events') %}
    {% if entry.stad not in stad_array %}
        {% set stad_array = stad_array|merge([entry.stad]) %}
        {{ entry.stad }}
    {% endif %}
{% endfor %}

Hope this helps!

> **Comments:**
> **username_0**: Thanks for the reply :) However, the other option is easier  
> **username_2**: Agreed! Glad you found a solution :)  

---

