2

I'm trying to suppress display of expired events (events that occurred in the past) on the Solspace month calendar. I'm using the out-of-the-box templates included with Solspace Calendar for Craft. Initially, I thought that there would be a start and end range for the calendar.month function:

{% set month = craft.calendar.month({
    date: targetDate,
    calendar: calendarHandle,
}) %}

But looking at the documentation, there are no parameters to pass. (https://solspace.com/craft/calendar/docs/calendar.month/)

So, I looked at what is happening, and it seems that the start and end should be set on the event object (https://solspace.com/craft/calendar/docs/event/)

In the month template, the event object is called here:

{% for event in day.events %}
    {% include "cal/layouts/_event.html" %}
{% endfor %}

And this is what is returned:

{% set classes = "" %}
{% set classes = classes ~ (event.allDay ? " all_day") %}

{% if event.multiDay %}
    {% set classes = classes ~ " multi_day" %}
    {% set classes = classes ~ (day.containsDate(event.startDate) ? " first_day") %}
    {% set classes = classes ~ (day.containsDate(event.endDate) ? " last_day") %}
{% endif %}

{% set style = "" %}
    {% if event.multiDay or event.allDay %}
        {% set style %}
    style="background-color: {{ event.calendar.lighterColor }} !important;
        border-color: {{ event.calendar.color }} !important;"
    {% endset %}
{% endif %}

{% if event.startDate.format('U') > now|date('U') %}

<div class="event tips{{ classes }}"{{ style }} data-toggle="popover">
        {% if event.multiDay %}
            <a href="{{ siteUrl }}cal/event/{{ event.id }}/{{ event.repeating ? event.startDate.format('Y/m/d') }}"
    style="color: {{ event.calendar.contrastColor }} !important;">
                {% autoescape false %}
                    {{ day.containsDate(event.startDate) or day.containsDate(event.endDate) ? event.title : "&nbsp;"|raw }}
                {% endautoescape %}
            </a>
        {% else %}
            {% if not event.allDay %}
                <span class="calendar-color" style="background-color: {{ event.calendar.color }};"></span>
            {% endif %}
                <a href="{{ siteUrl }}cal/event/{{ event.id }}/{{ event.repeating ? event.startDate.format('Y/m/d') }}"
                {% if event.allDay %}style="color: {{ event.calendar.contrastColor }};"{% endif %}>
                    {{ event.title }}
                </a>
        {% endif %}

    {% include "cal/layouts/_event_popover.html" %}
</div>

{% endif %}

I assume this is where I would set a date range, but I'm not really clear where I would set it?

UPDATE: I managed to get this working by wrapping the event output in a conditional:

{% if event.startDate.format('U') > now|date('U') %}

I added this to the code above.

2

The solution is to wrap the event output in a conditional that compares the event startdate to now. I've updated the question to reflect this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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