Skip to content

Instantly share code, notes, and snippets.

@davidhellmann
Created February 14, 2019 15:53
Show Gist options
  • Save davidhellmann/d754b33a9984565fec045f9d2e4d5ff5 to your computer and use it in GitHub Desktop.
Save davidhellmann/d754b33a9984565fec045f9d2e4d5ff5 to your computer and use it in GitHub Desktop.
{# -- Block: Event Highlights -- #}
{% block eventHighlights %}
{% set currentDateString = now.format('Y-m-d') %}
{% set nextEvents = craft.entries()
.section('events')
.orderBy('startDate asc')
.limit(4)
.where('content.field_requiresParticipationFromBeginning = FALSE AND content.field_endDate IS NULL AND content.field_startDate >="' ~ currentDateString ~ '"')
.orWhere('content.field_requiresParticipationFromBeginning = FALSE AND content.field_endDate >= "' ~ currentDateString ~ '"')
.orWhere('content.field_requiresParticipationFromBeginning = TRUE AND content.field_startDate >"' ~ currentDateString ~ '"')
%}
{% set highlightEvents = craft.entries()
.section('events')
.orderBy('startDate asc')
.limit(4)
.eventHighlight(true)
.where('content.field_requiresParticipationFromBeginning = FALSE AND content.field_endDate IS NULL AND content.field_startDate >="' ~ currentDateString ~ '"')
.orWhere('content.field_requiresParticipationFromBeginning = FALSE AND content.field_endDate >= "' ~ currentDateString ~ '"')
.orWhere('content.field_requiresParticipationFromBeginning = TRUE AND content.field_startDate >"' ~ currentDateString ~ '"')
.andWhere(('elements.id != ' ~ nextEvents.first().id) ~
((nextEvents.nth(1)) ? ') AND (elements.id != ' ~ nextEvents.nth(1).id : '') ~
((nextEvents.nth(2)) ? ') AND (elements.id != ' ~ nextEvents.nth(2).id : '') ~
((nextEvents.nth(3)) ? ') AND (elements.id != ' ~ nextEvents.nth(3).id : '')
)
%}
{% if highlightEvents | length < 4 %}
{% set furtherEvents = craft.entries()
.section('events')
.orderBy('startDate asc')
.limit(4 - highlightEvents | length)
.offset(4)
.where('content.field_requiresParticipationFromBeginning = FALSE AND content.field_endDate IS NULL AND content.field_startDate >="' ~ currentDateString ~ '"')
.orWhere('content.field_requiresParticipationFromBeginning = FALSE AND content.field_endDate >= "' ~ currentDateString ~ '"')
.orWhere('content.field_requiresParticipationFromBeginning = TRUE AND content.field_startDate >"' ~ currentDateString ~ '"')
.andWhere(((highlightEvents.one()) ? 'elements.id != ' ~ highlightEvents.first().id : '') ~
((highlightEvents.nth(1)) ? ') AND (elements.id != ' ~ highlightEvents.nth(1).id : '') ~
((highlightEvents.nth(2)) ? ') AND (elements.id != ' ~ highlightEvents.nth(2).id : '') ~
((highlightEvents.nth(3)) ? ') AND (elements.id != ' ~ highlightEvents.nth(3).id : '')
)
.all()
%}
{% set highlightEvents = highlightEvents | merge(furtherEvents) | supersort('sortAs', '{ startDate.format(\'Y-m-d\') }') %}
{% endif %}
{% include '_organisms/teaserDateSitebar/_template.html' with {
opt: {
headline: 'Weitere Termine' | t,
link: craft.entries().section('pages').type('events').one().url,
craftEvents: highlightEvents ?? null,
modifiers: ['grey'],
}
} only %}
{% endblock %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment