I have a section called "events" in which I have a table field that contains dates and times of these events.
So I want to order my events by date and within each day by time.
I thought of mergin an array that contains only the basic stuff and the Id to output the rest of the entry. (yes! I will cache the template).
This is how far I got, but I am struggling on how to first order by date, and then within a day, by time.
{% set entries = craft.entries.section('events').limit(null) %}
{% set dates = [] %}
{% for entry in entries %}
{% set table = entry.cf_dates_table %}
{% for row in table if row.startDate %}
{% set dates = dates|merge(
[{
'startDate': row.startDate,
'startTime': row.startTime|date('G:i'),
'endTime': row.endTime|date('G:i'),
'id': entry.id,
'uniqueId': entry.id ~ '-' ~ loop.index,
}]
)%}
{% endfor %}
{% endfor %}
<div id="list_container">
{% for date in dates|sort() %}
{{ date.startDate|date('l, d. F') }} {{ date.startTime }} – {{ date.endTime }}, {{ date.id }}<br />
{% endfor %}
</div>
I could imagine grouping the array by the day and then sort them within each day. But I can't get it to work.
Could somebody point me into the right direction?
Is this a viable approach?
Cheers
Stefan
asort()
. Maybe you could pull it off with something like github.com/TopShelfCraft/SuperSort#advanced-as-sorting