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?

up vote 5 down vote accepted

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.

  • That was an informative article; and both solutions worked just fine. Thanks for your help. – adamell Nov 20 '13 at 21:23

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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