{% set the_events = events|sort(attribute="start_datetime") %}

{% if filter == "upcoming" %}
	{% set the_events = events|sort(attribute="start_datetime")|rejectattr("has_passed")%}
{% elif filter == "passed" %}
	{% set the_events = events|sort(attribute="start_datetime", reverse=true)|selectattr("has_passed")%}
{% endif %}

{% if events|length > 0 %}
	
	<ul class='list--list'>
{% for item in the_events %}
		
				<li class="list__item">
				
					<span class="date">{{ item['start_datetime'] | prettydate }} </span>
					<b>{{ item['title'] }}</b>
					{% if item.has_passed and item.has_log %}
						<a href="/events/{{ item['slug'] }}.html" class="link">
							<b>Read more</b>
						</a>
					{% elif not item.has_passed %}
						<a href="https://calendar.klank.school/event/{{ item['slug'] }}" class="link">
							Join!
						</a>
					
					{% endif %}
					
				</li>

		
		{% endfor %}

	</ul>
{% endif %}