This document is for an older version of
Calendar
.
View latest version →
Templating
Month object
A Month object holds in itself a list of all Events that fall into this month, as well as gives the possibility to iterate over Week object's that fall into the range of this Month object.
Properties
date
- A Date object of the starting date of the event duration
- For a Month object of April 2023, this would return the Date object of
2023-04-01
startDate
- Basically the same as the
date
property
- Basically the same as the
endDate
- The ending date of the Month object's month, e.g -
2023-04-30
in this case
- The ending date of the Month object's month, e.g -
previousDate
- Returns a Date object of the previous month relative to the
date
property, e.g.2023-03-01
in this case
- Returns a Date object of the previous month relative to the
nextDate
- Returns a Date object of the next month relative to the
date
property, e.g.2023-05-01
in this case
- Returns a Date object of the next month relative to the
events
- Contains a list of Events that fall into this Month object's range
eventCount
- The number of events in the
events
property
- The number of events in the
Methods
dateRange(int before, int after)
- Returns a list of Date objects ranging
before
number of months beforedate
andafter
number of months afterdate
- E.g.
month.dateRange(6, 6)
would return a list starting from2015-10-01
and ending in2023-10-01
- Returns a list of Date objects ranging
containsDate(dateObject)
- Returns true if the
dateObject
provided is within the Month object's date range - E.g.
month.containsDate(event.startDate)
would return true if the Month object would be April 2023, and theevent.startDate
would be2023-04-15
, but false if theevent.startDate
would be2023-03-31
- Returns true if the
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 %}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
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 %}
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
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 %}
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10