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, 2016 and week starting day of Sunday, this would return the Date object of 2016-04-10 with the starting day of the week set to Sunday
  • startDate #
    • Basically the same as the date property
  • endDate #
    • The ending date of the Week object's week, e.g - 2016-04-16 in this case
  • previousDate #
    • Returns a Date object of the previous week relative to the date property, e.g. 2016-04-03 in this case
  • nextDate #
    • Returns a Date object of the next week relative to the date property, e.g. 2016-05-17 in this case
  • events #
    • Contains a list of Events that fall into this Week object's range
  • eventCount #
    • The number of events in the events property

Methods

  • dateRange(int before, int after) #
    • Returns a list of Date objects ranging before number of weeks before date and after number of weeks after date
    • E.g. week.dateRange(6, 6) would return a list starting from 2016-02-28 and ending in 2016-05-22
  • 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, 2016 starting on Sunday, and the event.startDate would be 2016-04-10, but false if the event.startDate would be 2016-04-09

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

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

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