<p>Instead of grabbing <em>all</em> entries in the <code>eventsEntry</code> section, then filtering by the current date/time, you could do the filtering on the database side first, so you're returning only the entries you're interested in.</p>

<p>Something like this:</p>

<pre><code>{% set pastEvents = craft.entries.section('eventsEntry').eventdate('&lt;= ' ~ now|atom) %}

{% for date, entries in pastEvents | group("pastEvents.eventdate|date('Y')") %}
    &lt;h4&gt;{{ date }}&lt;/h4&gt;

    &lt;ul&gt;
        {% for event in pastEvents.all() %}
            &lt;li&gt;
                {{ event.eventdate|date('d/m/y') }}
                {{ event.title }}
            &lt;/li&gt;
        {% endfor %}
    &lt;/ul&gt;
{% endfor %}
</code></pre>

CC BY-SA 4.0
2018-06-13T18:43:22.277Z
2018-06-13T18:43:22.277Z
Brad Bell
<p>I've hacked this together to create an event archive listing, and although it works, I'm wondering if it's 'correct' or could be done more succinctly?</p>

<pre><code>{% set pastEvents = craft.entries.section('eventsEntry').orderBy('eventDate') %}
   {% for date, entries in pastEvents | group("pastEvents.eventDate|date('Y')") %}
        &lt;h4&gt;{{ date }}&lt;/h4&gt;
            &lt;ul&gt;
                {% for event in pastEvents.all() if event.eventDate &lt;= now %}
                &lt;li&gt;
                    {{ event.eventDate|date('d/m/y') }}
                    {{ event.title }}
                &lt;/li&gt;                   
                {% endfor %} 
            &lt;/ul&gt;   
   {% endfor %}
</code></pre>

CC BY-SA 4.0
2018-06-12T18:45:13.783Z
Looks good to me. For the most part if it works for you it's correct.
Simon Kuran
<templating>
Template for event archive
# Template for event archive

(Asked by: username_0 on 2018-06-12)

I've hacked this together to create an event archive listing, and although it works, I'm wondering if it's 'correct' or could be done more succinctly?
{% set pastEvents = craft.entries.section('eventsEntry').orderBy('eventDate') %}
   {% for date, entries in pastEvents | group("pastEvents.eventDate|date('Y')") %}
        {{ date }}
            
                {% for event in pastEvents.all() if event.eventDate <= now %}
                
                    {{ event.eventDate|date('d/m/y') }}
                    {{ event.title }}
                                   
                {% endfor %} 
               
   {% endfor %}

**Tags:** templating
> **Comments:**
> **username_1**: Looks good to me. For the most part if it works for you it's correct.  

---

## 1 answers

### Answer by username_2 on 2018-06-13. Score: 1 | Accepted answer

Instead of grabbing all entries in the eventsEntry section, then filtering by the current date/time, you could do the filtering on the database side first, so you're returning only the entries you're interested in.
Something like this:
{% set pastEvents = craft.entries.section('eventsEntry').eventdate('<= ' ~ now|atom) %}

{% for date, entries in pastEvents | group("pastEvents.eventdate|date('Y')") %}
    {{ date }}

    
        {% for event in pastEvents.all() %}
            
                {{ event.eventdate|date('d/m/y') }}
                {{ event.title }}
            
        {% endfor %}
    
{% endfor %}


---

