4

Is it possible to loop through the list of entries and filter out any that have the same ID as any of the other entries (duplicates)? I have a specific case where this is an issue. I want to keep the first entry, but filter out the rest of them. I'm thinking it might work something like this...

  {% for event in events %}
    {% IF FIRST INSTANCE OF ENTRY %}
      {{ event.title }}
    {% endif %}
  {% endfor %}
Ben Shoults
  • 316
  • 2
  • 8

1 Answers1

6

I'd probably try to filter those out in your initial query, but if you've already got them, something like this should work:

{% set existingIds = [] %}

{% for event in events %}
    {% if event.id not in existingIds %}
        {{ event.title }}

        {% set existingIds = existingIds|merge([event.id]) %}
    {% endif %}
{% endfor %}
Brad Bell
  • 67,440
  • 6
  • 73
  • 143
  • Of course that worked like a charm. Thanks. I tried to close that block on line 7, but the edit had to be 6 characters. – Ben Shoults Apr 09 '16 at 02:17