1

We need to tell whether the user has chosen a specific date or has just defaulted to our calendar:

  • example.com/calendar

  • example.com/calendar/11/31/2013

We're trying the following:

{if segment_2 == ""}
  {exp:calendar:cal date_range_start="today" date_range_end="today" show_days="1" pad_short_weeks="n"}
{if:else}
  {exp:calendar:cal date_range_start="{segment_4}-{segment_2}-{segment_3}" date_range_end="{segment_4}-{segment_2}-{segment_3}" show_days="1" pad_short_weeks="n"}
{/if}
  ... do stuff with the events for the given day here.
{/exp:calendar:cal}

When we go to the /calendar page all of the data returned is fine, however, when we go to a specific date page, the data returned is for the current day (ie the data that's returned on the /calendar page).

Does anybody know as to why this is happening?

1 Answer 1

5

Just simple conditionals are parsed before the modules and plugins. Simple ones are the conditionals using just if and just early parsed variables. segment_N are early parsed variables, but your conditionals have an if:else.

So, try this:

{if segment_2 == ""}
  {exp:calendar:cal date_range_start="today" date_range_end="today" show_days="1" pad_short_weeks="n"}
{/if}
{if segment_2}
  {exp:calendar:cal date_range_start="{segment_4}-{segment_2}-{segment_3}" date_range_end="{segment_4}-{segment_2}-{segment_3}" show_days="1" pad_short_weeks="n"}
{/if}
  ... do stuff with the events for the given day here.
{/exp:calendar:cal}

Or this:

{exp:calendar:cal 
    {if segment_2 == ""}
        date_range_start="today" date_range_end="today"
    {/if}
    {if segment_2}
        date_range_start="{segment_4}-{segment_2}-{segment_3}" date_range_end="{segment_4}-{segment_2}-{segment_3}"
    {/if} 
    show_days="1" 
    pad_short_weeks="n"
}
  ... do stuff with the events for the given day here.
{/exp:calendar:cal}

This article about this subject is really good.

1
  • That was an informative article; and both solutions worked just fine. Thanks for your help. Commented Nov 20, 2013 at 21:23

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.