Calendar Calendar for Craft

Templating

Searching Events

This page serves as an example of how to perform basic searching into Solspace Calendar events. Some of the paths assume you're working with the demo templates that come with Calendar.

Searching via calendar.month

{% set searchTerm = craft.app.request.getParam("search") %}

<div>
  <form method="get">
    <label class="control-label">
      Search for something
    </label>
    <input type="text"
      name="search"
      class="form-control"
      placeholder="Search..."
      value="{{ searchTerm }}"
    />
  </form>
</div>

{% set eventOptions = {
  date: targetDate,
  calendar: calendarHandle,
  search: searchTerm ? "customFieldHandle:"~searchTerm : null
} %}
{% set month = craft.calendar.month(eventOptions) %}

<table id="month_calendar_inner" class="table table-bordered">
  <thead>
  <tr id="days_of_week" class="active">
    {% for day in month|first %}
      <th class="day_of_week">
        {{ day.date.format('l') }}
      </th>
    {% endfor %}
  </tr>
  </thead>
  <tbody>
  {% for week in month %}
    <tr>
    {% for day in week %}
      {% if month.containsDate(day.date) %}
        <td class="day_cell{{ day.date.isToday ? " today" }}">
          <div class="date{{ day.eventCount ? " has_events" }}">
            <a class="num" href="{{ siteUrl }}calendar_demo/day/{{ segment2 == 'calendar' ? "calendar/"~segment3~"/" }}{{ day.date.format('Y/m/d') }}">
              {{ day.date.format('j') }}
            </a>
          </div>
      {% else %}
        <td class="day_cell out_of_range">
          <div class="date">
            <span class="num">
              {{ day.date.format('j') }}
            </span>
          </div>
      {% endif %}
        {% for event in day.events %}
          {% include "calendar_demo/layouts/_event.html" %}
        {% endfor %}
        </td>
    {% endfor %}
    </tr>
  {% endfor %}
  </tbody>
</table>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61

Searching via calendar.events

{% set searchTerm = craft.app.request.getParam("search") %}

<div>
  <form method="get">
    <label class="control-label">
      Search for something
    </label>
    <input type="text"
      name="search"
      class="form-control"
      placeholder="Search..."
      value="{{ searchTerm }}"
    />
  </form>
</div>

{% set eventOptions = {
  rangeStart: targetStartDate,
  rangeEnd: targetEndDate,
  limit: 15,
  search: searchTerm ? "customFieldHandle:"~searchTerm : null
} %}

{% paginate craft.calendar.events(eventOptions) as pageInfo, events %}

{% for event in events %}
  <div>
    {{ event.title }}
  </div>
{% endfor %}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30