Skip to main content

Export Query

The calendar.export template query lets you export all or specific calendar events as an ICS formatted file. This will cause the user to receive a file download dialogue, and allow them to import the event(s) into a calendaring app like Apple Calendar or Google Calendar.

Make sure to pass events without loading their occurrences, since the exporter uses the RRule to specify how it recurs!

​Parameters

The calendar.export template function is fairly simple in that it receives a list of events generated by the calendar.events function. Additionally, there is 1 optional parameter available:

{{ craft.calendar.export(events, {timezone: "America/New_York"}) }}
  • timezone #
    • Allows you to simulate a localized timezone. By default, Calendar dates are stored as floating timezones, so an event with start time of 1pm would have a "floating" time of 1pm for UTC±0. If you specify "America/New_York" (UTC-4), the start time of the event will still show as 1pm, but pretend to be on a New York/UTC-4 timezone. If you then viewed this exported event in a timezone outside of UTC-4 such as UTC-5, the start time would display as 12pm. This feature is more-so available as a workaround for Google Calendar not correctly supporting floating timezones.
    • Specify the same format Craft does... Region/City, e.g. timezone: "America/New_York".
    • Warning: Dates/times will be will be localized (changed) for users outside of the specified timezone.

​Usage in Templates

A basic example with floating timezones (the same dates/times forced for everyone, e.g. 6:30pm is 6:30pm regardless of which timezone you're in):

{% set events = craft.calendar.events({
calendarId: [1, 3, 5],
rangeStart: "1 year ago",
rangeEnd: "5 years",
loadOccurrences: false
})) %}

{{ craft.calendar.export(events) }}

An example where you can simulate a localized timezone that will be localized for users outside of the specified timezone (more-so as a workaround for Google Calendar not correctly supporting floating timezones:

{% set events = craft.calendar.events({
calendarId: [1, 3, 5],
rangeStart: "1 year ago",
rangeEnd: "5 years",
loadOccurrences: false
})) %}

{{ craft.calendar.export(events, {timezone: "America/New_York"}) }}