Month Query
The calendar.month template query assembles a Month object containing its events and allows for iteration over it to access all Week objects contained within, which in turn contain their respective Day objects, which in turn contain their respective Hour objects.
Parameters
date
- A date string representing a date within the month that should be compiled.
"march 2023"
is a validdate
value"2023-03-01"
or even"2023-03-15 12:33"
would be valid and return the Month object for March 2023
calendar
- Handle of the calendar, e.g.
"holidays"
, or an array of handles:["holidays", "football"]
. - Use
"not holidays"
to select all calendars EXCEPT the Holidays calendar
- Handle of the calendar, e.g.
calendarId
- An ID of the calendar, or array of ID's, e.g.
[1, 2, 3]
- If you want to select all calendars EXCEPT the calendar with an ID of 1, use
"not 1"
- An ID of the calendar, or array of ID's, e.g.
allDay
- Selects only events that are set to be All Day events went set to
true
.
- Selects only events that are set to be All Day events went set to
authorId
- Selects events from specific author ID's
limit
- Supply an
int
to limit the amount of events returned
- Supply an
orderBy
- Override default sort order by for each day with this parameter, e.g.
orderBy: "startDate ASC"
- Override default sort order by for each day with this parameter, e.g.
status
- By default,
live
is used, showing only enabled events - Can be set to
disabled
to show disabled events - Or
null
to show all events regardless of their status
- By default,
loadOccurrences
- Set this to
false
to not load any recurring events. Default istrue
. - When setting this to
false
, Calendar will display only the very first occurrence in the results ONLY if that same occurrence falls within the Month date range. It will NOT just show the next recurrence available, and does NOT show any events that just have recurrences within the Month date range.
- Set this to
firstDay
- An
int
value representing the first day of week. - Defaults to the currently logged in user's first day of week.
- If user not logged in, it defaults to the global First Day of Week Craft setting
- Accepts
int
values from0-6
,0
being Sunday,6
being Saturday
- An
search: "customField:myvalue*"
- Works just like regular Craft Searching.
There's currently a known issue where searches combined with
calendar
parameter will not work. UsecalendarId
instead for now.
- Works just like regular Craft Searching.
relatedTo: event.id
- Works just like regular Craft Relations.
Usage in Templates
Iterate through weeks and days of the month
{% set month = craft.calendar.month({
date: "today",
calendar: ["holidays", "sports"]
}) %}
{% for week in month %}
{% for day in week %}
{% for event in day.events %}
<div style="{{ event.calendar.color }};">
{{ event.title }}
</div>
{% endfor %}
{% endfor %}
{% endfor %}
Iterate through all events in the month
{% set month = craft.calendar.month({
date: "today",
calendar: ["holidays", "sports"]
}) %}
{% for event in month.events %}
<div style="{{ event.calendar.color }};">
{{ event.title }}
</div>
{% endfor %}
Show only events which start in weekends
{% set month = craft.calendar.month({
date: "today",
calendar: ["holidays", "sports"]
}) %}
{% for event in month.events if event.startDate.weekend %}
<div style="{{ event.calendar.color }};">
{{ event.title }}
</div>
{% endfor %}