Logo dispositiontools

Minical template functions

Getting started

Creating the Minical calendar object is very easy.

  • Firstly get all the elements you'd like to layout in a calendar.
  • Create the options object
  • Create the calendar object

{# Get your elements #}
{% set elements = craft.entries.section('events').all() %}

{# Create the settings object  #}
{% set calOptions = {
  elements: elements,
 } %}

{# create the calendar object #}
{% set calendar = craft.minical.cal( calOptions ) %}


Now you have the calendar object you can iterate over the months, weeks, days and daily elements and style however you'd like.


{# iterate over the months #}
{% for month in calendar.months %}
<div class="">
  <table>
    <thead>
      <tr>
          <th colspan="7">{{ month.monthStartDate|date("M - Y") }}</th>
      </tr>
      <tr>
      	{# iterate over the day headers #}
        {% for dayHeader in calendar.dayHeaders %}
          <th>{{ dayHeader }}</th>
        {% endfor %}
      </tr>
    </thead>
  <tbody>
  {# iterate over the weeks #}
  {% for week in month.weeks %}
    <tr>
    {# iterate over the days #}
      {% for day in week.days %}
          <td
          	{# show the date if the cell in the table is an actualday  #}	
            {% if not day.blank %}
            {{ day.dayDate|date("d") }}
            {% endif %}
			
			{# Show a symbol if the day has elements  #}	
            {% if day.hasElements %} ! {% endif %}
            
			{# iterate over the elements in that day. #}
			{# These elements are the full element array item that was originally given in the settings object  #}	
            {% for element in day.elements %}
              <a href="{{ element.url }}">{{ element.title }}</a>
            {% endfor %}
          </td>
      {% endfor %}
    </tr>
  {% endfor %}
  </tbody>
  </table>
</div>
{% endfor %}


Parameters

If you just pass Minical a set of elements it will look for the first and last occurrences and then create the months to cover all of those dates.


Custom starting and ending months

You can choose your own starting and ending dates with the parameters

startDateString and endDateString

These take any string that can be parsed by php strtotime.


{% set calOptions = {
  startDateString:'2020-01-01',
  endDateString: '2020-12-31'
 } %}


Change the week starting date.

Minical defaults to the week starting on a Monday. You can choose your own starting date with the parameter:

firstDayOfTheWeek

This accepts a integer between 0 and 6.


{% set calOptions = {
  firstDayOfTheWeek:'0'
 } %}


Day title format

The plugin default is show the day titles as three letters long. You can choose another format using the dayTitleFormat parameter. This accepts any DateTime format string.

Ie to get the full day names use "l" (Lowercase L).


{% set calOptions = {
  dayTitleFormat:'l'
 } %}


Date field

The plugin defaults to checking the postDate of the element. If you are using a different date field you can use the dateField parameter.

This fields needs to be a DateTime type field.


{% set calOptions = {
  dateField:'showTime'
 } %}