This document is for an older version of
Calendar
.
View latest version →
Templating
Week object
A Week object holds in itself a list of all Events that fall into this week, as well as gives the possibility to iterate over Day object's that fall into the range of this Week object.
Properties
date
- A Date object of the starting date of the event duration
- For a Week object of April 15, 2023 and week starting day of Sunday, this would return the Date object of
2023-04-10
with the starting day of the week set to Sunday
startDate
- Basically the same as the
date
property
- Basically the same as the
endDate
- The ending date of the Week object's week, e.g -
2023-04-16
in this case
- The ending date of the Week object's week, e.g -
previousDate
- Returns a Date object of the previous week relative to the
date
property, e.g.2023-04-03
in this case
- Returns a Date object of the previous week relative to the
nextDate
- Returns a Date object of the next week relative to the
date
property, e.g.2023-05-17
in this case
- Returns a Date object of the next week relative to the
events
- Contains a list of Events that fall into this Week 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 weeks beforedate
andafter
number of weeks afterdate
- E.g.
week.dateRange(6, 6)
would return a list starting from2023-02-28
and ending in2023-05-22
- Returns a list of Date objects ranging
containsDate(dateObject)
- Returns true if the
dateObject
provided is within the Week object's date range - E.g.
week.containsDate(event.startDate)
would return true if the Week object would be April 15, 2023 starting on Sunday, and theevent.startDate
would be2023-04-10
, but false if theevent.startDate
would be2023-04-09
- Returns true if the
Usage in Templates
Iterate through days of the week
{% set week = craft.calendar.week({
date: "today",
calendar: ["holidays", "sports"]
}) %}
{% for day in week %}
{% for event in day.events %}
<div style="{{ event.calendar.color }};">
{{ event.title }}
</div>
{% endfor %}
{% endfor %}
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
Iterate through all events in the week
{% set week = craft.calendar.week({
date: "today",
calendar: ["holidays", "sports"]
}) %}
{% for event in week.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 weekdays
{% set week = craft.calendar.week({
date: "today",
calendar: ["holidays", "sports"]
}) %}
{% for event in week.events if event.startDate.weekday %}
<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