How to determine if there are events in a calendar? 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 %}
        &lt;option value="{{ siteUrl }}cal/{{ urlPart }}"{% if segment3 == calendar.handle %} selected="selected"{% endif %}&gt;
            {{ calendar.name }} - {{ calendar.event.occurrenceCount }}
        &lt;/option&gt;
    {% 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.
Looking at the docs 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 %}