3

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 %}
5

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 %}
  • 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 9 '16 at 2:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.