Event object

Event view

Properties

  • id #
    • The event's unique ID, which is also the element ID.
  • slug #
    • The event's unique URL slug.
  • title #
    • The event's title.
  • status #
    • The event's status.
  • enabled #
    • If the event is enabled.
  • authorId #
    • The event's author ID.
  • author #
    • The event's author.
  • startDate #
    • a Date object.
    • Can be formatted with .format("l, F j, Y \\a\\t g:ia")
    • If you'd like to have dates translatable, use startDateLocalized instead and format() with |date() filter, e.g. event.startDateLocalized|date("l, F j, Y g:ia").
  • endDate #
    • a Date object.
    • Can be formatted with .format("l, F j, Y \\a\\t g:ia")
    • If you'd like to have dates translatable, use endDateLocalized instead and format() with |date() filter, e.g. event.startDateLocalized|date("l, F j, Y g:ia").
  • duration #
    • a Duration object.
  • allDay #
    • a boolean value.
  • multiDay #
    • a boolean value.
  • repeating #
    • a boolean value.
  • rrule #
    • The RFC RRule string used by ICS.
  • readableRepeatRule #
    • a human readable string of the rrule.
  • simplifiedRepeatRule #
    • a simplified version of the repeat rule (e.g. Weekly).
  • isCurrentlyHappening #
    • Checks if the user's current time is between the event's start and end date.
    • Based on the logged in user's locale, or otherwise the site's default timezone.
  • isHappeningOn #
    • Checks if the specified date and time is between the event's start and end date.
    • Ex: {% if event.isHappeningOn('2017-03-07 4:30pm') %} Yes! {% endif %}
      • Time has a default of 00:00:00, so if not specified, only All Day events will evaluate to true.
  • calendar #
    • a Calendar object.
  • exceptions #
    • a list of exception dates for recurring objects.
  • occurrences #
    • a list of Event objects of all occurrences for repeating rules.
  • occurrenceCount #
    • the total number of occurrence results.
  • url #
    • the URL of the event, if available, generated from Event URL path setting for calendars.

You can also access any custom fields which you have added to events by directly calling their handle (the handle must not match any of the existing event properties).

Usage in Templates

You can also access any custom fields which you have added to events by directly calling their handle (the handle must not match any of the existing event properties). If you had a field called Event Description with a handle of eventDescription you would access it in the template like this:

{{ event.eventDescription }}
1

You could make sure such a property exists first, to prevent errors in case the field is deleted:

{% if event.eventDescription is defined %}
  {{ event.eventDescription }}
{% endif %}
1
2
3

Let's use a Date method to check if our event's start date is before the current Day's date

{# Print out the Y-m-d of start date if start date is before the Day date #}

{% if event.startDate.lt(day.date) %}
  {{ event.startDate.dateString }}
{% endif %}
1
2
3
4
5

Now let's print out the duration of the event, which is the amount of time in months, days, hours, etc from the event's start date until its end date

{# Print out the duration string #}
{# An example output would be "1d 5h 30m" #}

{{ event.duration.humanReadable }}

{# Print out a custom message if the duration in days is 1 or more #}

{% if event.duration.days >= 1 %}
  Event spans for {{ event.duration.days }} days
{% endif %}
1
2
3
4
5
6
7
8
9
10
Last Updated: 4/18/2019, 11:33:42 AM