1

I'm using a matrix inside a Super Table to organize events, and I'd like to order the events using the date field for each event.

I'm currently showing the first five events using limit then using offset to show the rest of the blocks after the first five. Then I'm separating future and past events using the date field. Like this:

First five upcoming events:

{% for block in block.eventList.limit(5) %}
     {% if block.eventDate >= now %}
          {{ block.eventTitle }}
     {% endif %}
{% endfor %}

The rest of the upcoming events:

{% for block in block.eventList.offset(5) %}
     {% if block.eventDate >= now %}
          {{ block.eventTitle }}
     {% endif %}
{% endfor %}

All past events:

{% for block in block.eventList %}
     {% if block.eventDate <= now %}
          {{ block.eventTitle }}
     {% endif %}
{% endfor %}

This works fine as is, but it doesn't sort the events within the sections by the date field. How can I add that?

1

I hope I am not completely missing the point, but I guess like that:

Initial 5:

{% for block in block.eventList.eventDate('>=' ~ (now|atom)).orderBy('eventDate asc').limit(5).all() %}
     {{ block.eventTitle }}
{% endfor %}

rest:

{% for block in block.eventList.eventDate('>=' ~ (now|atom)).orderBy('eventDate asc').offset(5).all() %}
          {{ block.eventTitle }}
{% endfor %}

past events:

{% for block in block.eventList.eventDate('<' ~ (now|atom)).orderBy('eventDate desc').all() %}
     {{ block.eventTitle }}
{% endfor %}

you will probably need to change the date('Y-m-d') format

  • Thanks so much! This works, except it doesn't output anything for past events (even though there are events with dates prior to today). Any reason that could be? Thanks again – univers_ May 16 '20 at 22:03
  • ok, I just learned something here: the filter to use is not date(...) but |atom instead. With this it works. I also player around a little bit with the date filter to check that and never got it to work. don't know why... anyway, use |atom. And parenthesis. I changed the answer above. – Matthias Redl-Mann May 17 '20 at 20:07
  • ok, the real solution: I was missing the parenthesis with (now|atom). You could also go (now|date('Y-m-d')) if you e.g. just wanted to consider the day but not the time of now, which |atom does. – Matthias Redl-Mann May 17 '20 at 20:13

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.