Answers.Body: <p>Looking at the <a href="https://solspace.com/craft/calendar/docs/calendar.events/#param-calendar" rel="nofollow noreferrer">docs</a> you can search for <code>events</code> for a certain <code>calander</code> by including the <code>id</code> or the <code>handle</code> in your query.</p>
  
  <pre><code>{% set calendars = craft.calendar.calendars({
      limit: 100,
      order: "name",
      sort: "asc"
  }) %}
  
  {% for calendar in calendars %}
      {% set events = craft.calendar.events({
          calendarId: calendar.id
      }) %}
  
      {% if events|length %}
          // there are events
      {% else %}
          // calendar has no events
      {% endif %}
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-23T14:20:05.940Z
Answers.LastActivityDate: 2018-03-23T14:43:39.840Z
Answers.LastEditDate: 2018-03-23T14:43:39.840Z
Answers.UserDisplayName: Robin Schambach
Body: <p>I need to write a conditional that determines if events actually exist in a calendar. I only want to display an option in the the select dropdown IF the calendar has events:</p>
  
  <pre><code>{% set calendars = craft.calendar.calendars({
      limit: 100,
      order: "name",
      sort: "asc"
  }) %}
  
  {% set events = craft.calendar.events({
      calendarId: calendar.id
  }) %}
  
  {% for calendar in calendars %}
  
      {# determine what the URL should look like based on the current URL structure #}
  
      {% if segment1 == '' %}
          {% set urlPart = "month/calendar/" ~ calendar.handle ~ "/" ~ month.date.format('Y/m') ~ "#1" %}
      {% elseif segment3 is not empty and segment4 is not empty %}
          {% set urlPart = "month/calendar/" ~ calendar.handle ~ "/" ~ segment4 ~ "/" ~ segment5 ~ "#2" %}
      {% else %}
          {% set urlPart = "month/calendar/" ~ calendar.handle ~ "/" ~ segment2 ~ "/" ~ segment3 ~ "#3" %}
      {% endif %}
  
      {# I need a conditional here that outputs an option only IF there are events in the calendar #}
  
      {% if events %}
          &lt;option value="{{ siteUrl }}cal/{{ urlPart }}"{% if segment3 == calendar.handle %} selected="selected"{% endif %}&gt;
              {{ calendar.name }} - {{ calendar.event.occurrenceCount }}
          &lt;/option&gt;
      {% endif %}
  
  {% endfor %}
  </code></pre>
  
  <p>UPDATE: I expanded this out so you can see everything. Unfortunately, this is still outputting all calendars even if the calendar has no events.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-03-23T14:34:05.990Z
Comments.Text: Of course you have to search the events for each calendar.... so you have to search the events inside your loop. Your calendar variable is not even defined at this point
Comments.UserDisplayName: Robin Schambach
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-03-23T14:38:51.410Z
Comments.Text: I apologize, but I'm a newbie to Craft (migrating from EE). Perhaps you could help me with a code example?
Comments.UserDisplayName: Vaughn D. Taylor
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2018-03-23T14:44:31.673Z
Comments.Text: This has nothing to do with a certain CMS/Framework it's just about basic code logic, I updated my answer
Comments.UserDisplayName: Robin Schambach
Tags: <conditional><plugin-solspacecalendar>
Title: How to determine if there are events in a calendar?
ThreadText: # How to determine if there are events in a calendar?
  
  (Asked by: username_0 on 2018-03-23)
  
  I need to write a conditional that determines if events actually exist in a calendar. I only want to display an option in the the select dropdown IF the calendar has events:
  
  ```
  {% set calendars = craft.calendar.calendars({
      limit: 100,
      order: "name",
      sort: "asc"
  }) %}
  
  {% set events = craft.calendar.events({
      calendarId: calendar.id
  }) %}
  
  {% for calendar in calendars %}
  
      {# determine what the URL should look like based on the current URL structure #}
  
      {% if segment1 == '' %}
          {% set urlPart = "month/calendar/" ~ calendar.handle ~ "/" ~ month.date.format('Y/m') ~ "#1" %}
      {% elseif segment3 is not empty and segment4 is not empty %}
          {% set urlPart = "month/calendar/" ~ calendar.handle ~ "/" ~ segment4 ~ "/" ~ segment5 ~ "#2" %}
      {% else %}
          {% set urlPart = "month/calendar/" ~ calendar.handle ~ "/" ~ segment2 ~ "/" ~ segment3 ~ "#3" %}
      {% endif %}
  
      {# I need a conditional here that outputs an option only IF there are events in the calendar #}
  
      {% if events %}
          <option value="{{ siteUrl }}cal/{{ urlPart }}"{% if segment3 == calendar.handle %} selected="selected"{% endif %}>
              {{ calendar.name }} - {{ calendar.event.occurrenceCount }}
          </option>
      {% endif %}
  
  {% endfor %}
  
  ```
  
  UPDATE: I expanded this out so you can see everything. Unfortunately, this is still outputting all calendars even if the calendar has no events.
  
  **Tags:** conditional, plugin-solspacecalendar
  
  > **Comments:**
  > **username_1**: Of course you have to search the events for each calendar.... so you have to search the events inside your loop. Your calendar variable is not even defined at this point  
  > **username_0**: I apologize, but I'm a newbie to Craft (migrating from EE). Perhaps you could help me with a code example?  
  > **username_1**: This has nothing to do with a certain CMS/Framework it's just about basic code logic, I updated my answer  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-03-23. Score: 3 | Accepted answer
  
  Looking at the [docs](https://solspace.com/craft/calendar/docs/calendar.events/#param-calendar) you can search for `events` for a certain `calander` by including the `id` or the `handle` in your query.
  
  ```
  {% set calendars = craft.calendar.calendars({
      limit: 100,
      order: "name",
      sort: "asc"
  }) %}
  
  {% for calendar in calendars %}
      {% set events = craft.calendar.events({
          calendarId: calendar.id
      }) %}
  
      {% if events|length %}
          // there are events
      {% else %}
          // calendar has no events
      {% endif %}
  {% endif %}
  
  ```
  
  
  ---
  
  