This document is for an older version of

Calendar

.

View latest version →

Calendar Calendar for Craft

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 2016, this would return the Date object of 2016-04-01
  • startDate #
    • Basically the same as the date property
  • endDate #
    • The ending date of the Month object's month, e.g - 2016-04-30 in this case
  • previousDate #
    • Returns a Date object of the previous month relative to the date property, e.g. 2016-03-01 in this case
  • nextDate #
    • Returns a Date object of the next month relative to the date property, e.g. 2016-05-01 in this case
  • events #
    • Contains a list of Events that fall into this Month 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 months before date and after number of months after date
    • E.g. month.dateRange(6, 6) would return a list starting from 2015-10-01 and ending in 2016-10-01
  • 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 2016, and the event.startDate would be 2016-04-15, but false if the event.startDate would be 2016-03-31

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

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

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