This document is for an older version of
Calendar
.
View latest version →
Templating
Hour object
An Hour object holds in itself a list of all Events that fall into this hour.
Properties
date
- A Date object of the starting date of the event duration
- For an Hour object of April 15, 2023 at 5pm, this would return the Date object of
2023-04-15 17:00:00
startDate
- Basically the same as the
date
property
- Basically the same as the
endDate
- The ending date of the Hour object's hour, e.g -
2023-04-15 17:59:59
in this case
- The ending date of the Hour object's hour, e.g -
previousDate
- Returns a Date object of the previous hour relative to the
date
property, e.g.2023-04-15 16:00:00
in this case
- Returns a Date object of the previous hour relative to the
nextDate
- Returns a Date object of the next hour relative to the
date
property, e.g.2023-05-15 18:00:00
in this case
- Returns a Date object of the next hour relative to the
events
- Contains a list of Events that fall into this Hour 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 hours beforedate
andafter
number of hours afterdate
- E.g.
hour.dateRange(6, 6)
would return a list starting from2023-04-15 11:00:00
and ending in2023-04-15 23:00:00
assuming the Day object'sdate
is2023-04-15 17:00:00
- Returns a list of Date objects ranging
containsDate(dateObject)
- Returns true if the
dateObject
provided is within the Hour object's date range - E.g.
hour.containsDate(event.startDate)
would return true if the Hour object would be April 15, 2023 at 5pm, and theevent.startDate
would be2023-04-15 17:30:00
, but false if theevent.startDate
would be2023-04-16 18:00:00
- Returns true if the
Usage in Templates
Iterate through all events within the current hour
{% set hour = craft.calendar.day({
date: "now",
calendar: ["holidays", "sports"]
}) %}
{% for event in hour.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