Im really liking the ability to display a reminder of the days events, but have noticed that the response is not correctly sorted by time. Im using the following code:
The statement {% agenda.events|sort %} isn’t really doing anything the way you have it set up. You need to either save your sorted list to a variable, or move your sort to the for statement so the list is sorted prior to being looped over:
Your agenda for today: <p>
{% for event in agenda.events|sort(attribute='start') %}
{{ (event.start|as_datetime).strftime('%Y/%m/%d %H:%M') }} - {{ event.summary }}<br>
{% endfor %}
</p>
EDIT: The calendar.list_events service shown in the original post has been deprecated and replaced by the action calendar.get_events.
Thank you, I almost opened another issue for this, I was 99% of the way there, but I needed to add |sort(attribute=‘start’) and now I have this working perfectly!
I take that back, it appears that what I have is looping through each calendar and listing each individual calendars events in order, not sorting all the events in order.
Nowhere in your template are the events (or their string outputs) combined together… you need to use the namespace to hold the results of the loops so that all the agenda items are output as a list that can be sorted. Here’s one way to do that:
{% set ns = namespace(cal_events=[]) %}
{%- for key, value in agenda.items() %}
{%- for event in value.events %}
{%- set ns.cal_events = ns.cal_events + [(as_timestamp(event.start) | timestamp_custom('%H:%M'))~': '~ event.summary] %}
{%- endfor %}
{%- endfor %}
{{ ns.cal_events | sort | join('\n') if
ns.cal_events | count > 0 else 'Nothing to do Today!'}}
Note: This template is designed for a single day agenda.