0

I can't seem to be able to do any comparisons on the formatted event dates within the Solspace calendar. For example, in the following piece of code I'm trying to modify the mini-calendar example from the calendar docs (https://solspace.com/expressionengine/calendar/docs/month/) not to show links to any Mondays (because the company I work for is closed on Mondays):

<div>
    {if calendar:day_in_current_month} {!-- Only show day number for current month --}

        {if calendar:day_total_events && ('{calendar:day_date format="%D"}' != 'Mon')} {!-- Link to the day if there's events for it, if it's not a Monday --}
            <a href="{path='/visit/calendar/day'}/{calendar:day_date format='%Y/%m/%d'}/" id="day-link-{calendar:day_date format='%Y-%m-%d'}">
        {/if}

            {calendar:day_date format="%j"}

        {if calendar:day_total_events && ('{calendar:day_date format="%D"}' != 'Mon')}
            </a>
        {/if}

    {if:else} {!-- Don't show day number if day is not in current month --}
        <strong>&nbsp;</strong>
    {/if}
</div>

The != 'Mon' comparison fails on all entries, including the ones occurring on Mondays.

Similarly, on another page I need to not show any events within a specific category during the winter months, as follows:

{if !( ( ('{category_name}' == 'X') || ('{category_name}' == 'Y') ) && ( ({calendar:month_date format='%n'} < 11) || ({calendar:month_date format='%n'} > 3) ) )}  
    <li>
        <a id="category-link-{category_url_title}" href="/calendar/category/{category_url_title}">{category_name}</a>
    </li>
{/if}

This doesn't seem to work either -- i.e. all categories get displayed all the time.

Can anyone point out what I'm doing wrong in either or both of these cases?

Thanks!

Misha

  • I have the same problem, trying to compare month.. I'll give a try with the workaround below... and it works!.. Thanks! – Benoit L Mar 3 '17 at 15:43
1

There is currently limited support for conditionals due to performance reasons and because many of these date variables are timestamps set with UTC.

One workaround for now might be to use an embed to handle the parsing. This isn't a plug and play solution, but it should give you an idea of what options you have for adjusting your template:

{embed="calendar/conditional_check" date="{calendar:day_date format='%D'}"}

And in the embedded template:

{if embed:date == "Mon"}*{/if}

However, I have made a note about this for future consideration to allow for this functionality. :)

| improve this answer | |

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.