This document is for an older version of
Calendar
.
View latest version →
calendar.export function
The calendar.export template function 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.
TIP
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 of1pm
forUTC±0
. If you specify"America/New_York"
(UTC-4
), the start time of the event will still show as1pm
, but pretend to be on a New York/UTC-4 timezone. If you then viewed this exported event in a timezone outside ofUTC-4
such asUTC-5
, the start time would display as12pm
. 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.
- Allows you to simulate a localized timezone. By default, Calendar dates are stored as floating timezones, so an event with start time of
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) }}
2
3
4
5
6
7
8
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"}) }}
2
3
4
5
6
7
8