Overview
Element Field Types
Calendar includes Calendar Events and Calendar Calendars fieldtypes, which allows you to assign/relate events and whole calendars (ID's) to other element types such as Craft Entries and even other events themselves.
Calendar Events
The Calendar Events field type allows you to assign/relate events to other element types such as Craft Entries and even other Calendar events.
Creating an Events field
Creating a Calendar Events field is done just like any other fieldtype, here's an overview of the process:
- Go to the Settings area in Craft control panel. Click on Fields.
- Click the New field button in the top right corner.
- Name the field as you wish. For example: Related Events with a handle of relatedEvents.
- For the Field Type option, select Calendar Events from the list.
- 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.
- Limit limits the number of events you can select for this field.
- Selection Label is the text that will appear on the button which opens the Event selection pop-up dialog.
- Click the Save button in the top right corner to save the new field.
Your Calendar Events field is now available to be assigned to other sections.
How the Fieldtype works
The 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.
Use in Templates
You add the 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 %}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Calendar Calendars
The Calendar Calendars field type allows you to assign/relate whole calendars (ID's) to other element types such as Craft Entries. What actually is related is the calendar ID, thus allowing you to then pull in events for the given calendar attached to the Craft element.
Creating a Calendars field
Creating a Calendar Calendars field is done just like any other fieldtype, here's an overview of the process:
- Go to the Settings area in Craft control panel. Click on Fields.
- Click the New field button in the top right corner.
- Name the field as you wish. For example: Related Calendars with a handle of relatedCalendars.
- For the Field Type option, select Calendar Calendars from the list.
- Click the Save button in the top right corner to save the new field.
Your Calendar Calendars field is now available to be assigned to other sections.
How the Fieldtype works
The Calendar Calendars fieldtype lets the user choose 1 calendar to assign to any element: a section entry, categories, assets, etc.