You can use the
craft.calendars.month variable to produce a monthly calendar.
This variable returns a
CalendarMonthModel is an object that represents a calendar month, as well as a query for events that occur during the month.
This makes it easy to find all of the events in a month and display them in a grid layout or weekly list.
Adding parameters to the
- whether event information will be included in the calendar
- which events to include
- how days are grouped into weeks
CalendarMonthModel accepts the same parameters as an
(In other words, you can use all the parameters with
calendars.month that you can use with the
CalendarMonthModel also has some additional month-specific parameters:
The date from which the monthly calendar will be generated. (The generated monthly calendar will include the dates from the month in which calendarDay falls, plus any leading or trailing days at the beginning/end of the included weeks.) Accepts a DateTime object or a date string.
The day of the week on which to start the weeks of the calendar. Accepts a string: the full name of the weekday.
Whether or not to include the
EventModel objects for events that fall within the dates of the computed calendar. (This is set to
true by default, but if you only need the calendar, without any events, you can disable it to improve performance.) Accepts a boolean.
By default, when you fetch a
calendars.month, Craft Calendars automatically creates a corresponding
EventCrtieriaModel (based on the parameters you provide), fetches any matching events that occur during the month, and attaches them to the
However, you can use a
CalendarMonthModel to create a calendar view for any arbitrary month, whether or not is has Craft Calendars events attached.
The number of days in the given month.
A DateTime representing the beginning of the given month.
A DateTime representing the beginning of the next month.
A DateTime representing the beginning of the previous month.
A DateTime representing the first day on the calendar, including leading days from the previous month.
A DateTime representing the first day on the calendar, including trailing days from the next month.
A list of abbreviations of the week days, in order. (The order of week days changes based on the
weekStartDay parameter you provide.)
Each item is an array with
weekdayShort (“Sun”), and
weekdayFirst (“S”) properties.
An array list of the weeks in the month.
(This is the property you would loop through to create the ‘rows’ of a calendar grid view.)
Each item of
weeks has a single property:
Items in the
days array represents days in the week. Each day has these properties:
(These properties are described in detail below.)
A DateTime representing the calendar day.
A boolean representing whether the calendar day is a leading day from the previous month.
A boolean representing whether the calendar day is part of the given month.
A boolean representing whether the calendar day is a trailing day from the next month.
A boolean representing whether the calendar day is the given day from which the month was generated.
A boolean representing whether the calendar day is today.
A list of
EventModel objects, representing the events that occur on the calendar day.
This property will be empty if you have chosen to exclude events by setting
You can use this example template as a starting point to create a table-based calendar grid: