0

I have a drop down that lists all the Calendars. However I would like to only show Calendars that have an event assigned to them.

I need something like the show_empty tag for EE Category Archive: http://ellislab.com/expressionengine/user-guide/add-ons/channel/category_archive.html#show-empty

1 Answer 1

0

You can use {exp:calendar:calendars} to list calendars, and pass the {calendar_id} to {exp:calendar:events} or {exp:calendar:cal} to see if there are any event entries for that calendar.

Given that there can be variables clashes with common variables such as {total_results}, {count}, etc, you will likely need to embed the {exp:calendar:events} or {exp:calendar:cal} code.

Here's an example. In your template use:

<select name="something">
{exp:calendar:calendars}
  {embed="calendars/embed" calendar_id="{calendar_id}"}
{/exp:calendar:calendars}
</select>

Then, in /calendars/embed, use:

{exp:calendar:events calendar_id="{embed:calendar_id}" date_range_start="12 months ago" date_range_end="+12 months"}
    {if no_results}
    {/if}

    {if count == 1}
        [{calendar_id}] {calendar_title}<br />
    {/if}

{/exp:calendar:events}

Using a timeframe, with date_range_start="" and date_range_end="", large enough to cover your events is important, or else you only get a subset of the total events present for a calendar.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.