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
dateproperty
- Basically the same as the
endDate- The ending date of the Month object's month, e.g -
2023-04-30in 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
dateproperty, e.g.2023-03-01in 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
dateproperty, e.g.2023-05-01in 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
eventsproperty
- The number of events in the
Methods
dateRange(int before, int after)- Returns a list of Date objects ranging
beforenumber of months beforedateandafternumber of months afterdate - E.g.
month.dateRange(6, 6)would return a list starting from2015-10-01and ending in2023-10-01
- Returns a list of Date objects ranging
containsDate(dateObject)- Returns true if the
dateObjectprovided 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.startDatewould be2023-04-15, but false if theevent.startDatewould 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 %}
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 %}