This document is for an older version of

Calendar

.

View latest version →

Element Field Type

Because Solspace Calendar is an Element Type, you're able to assign/relate events to other element types such as Entries and even other events themselves.

Creating an Events field

Creating a Calendar Events field is done just like any other fieldtype, here's an overview of the process:

  1. Go to the Settings area in Craft control panel. Click on Fields.
  2. Click the New field button in the top right corner.
  3. Name the field as you wish. For example: Related Events with a handle of relatedEvents.
  4. For the Field Type option, select Calendar Events from the list.
  5. The Sources list lets you narrow down the possible assignable events to this field by calendar. Select all or whichever calendar(s) you'd like.
  6. Limit limits the number of events you can select for this field.
  7. Selection Label is the text that will appear on the button which opens the Event selection pop-up dialog.
  8. Click the Save button in the top right corner to save the new field.

Your Solspace Calendar Events field is now available to be assigned to other sections.

Create New Fieldtype

How the Fieldtype works

The Solspace Calendar Event fieldtype lets the user assign any events that have been created in the Calendar Events page to any element: a section entry, categories, assets, etc. Even events themselves.

Using Fieldtype

Using Fieldtype

Use in Templates

You add the Solspace Calendar Event fieldtype to your template code just like you would for any other field. Continuing off the example above (with handle of relatedEvents), your code would look something like this:

{% if entry.relatedEvents is defined and entry.relatedEvents is not empty %}
  <ul>
  {% for event in entry.relatedEvents.status(null).all %}
    <li>
      {{ event.title }} - {{ event.startDate.format("l, F j, Y \\a\\t g:ia") }}
      ({{ event.duration.humanReadable }})
      in {{ event.calendar.name }} calendar.
      {% if event.repeating %}
        Repeats {{ event.readableRepeatRule }}
      {% endif %}
    </li>
  {% endfor %}
  </ul>
{% else %}
  <p>No events related to this entry.</p>
{% endif %}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16