0

I am trying to use date_range_start="today" instead of date_range_start="{segment_3}-{segment_4}-01" if the user is on the current month displayed. I have this working properly for all other months except the current month. The problem is that events that have already passed are still showing up for the current month. Is there a conditional that I could use to check if it is the current month and then use date_range_start="today" in that case? Below is the loop that I am using.

{exp:calendar:cal 
    date_range_start="{segment_3}-{segment_4}-01"
    date_range_end="{segment_3}-{segment_4}-last" 
    show_months="1" 
    show_future_entries="yes" 
    dynamic="no" 
    event_limit="3" 
    paginate="bottom" 
    pad_short_weeks="n"}
1

The documentation of the rendering stages says that segment_variables, preload_replace:variable and current_time are parsed before the modules and plugins tags.

You can use all of them to conditionally set the parameter of the exp:calendar:cal.

For the conditional, format the current_time as the segment.

{if '{current_time format="%m"}' == segment_4}
    {preload_replace:pre-date_start="today"}
{if:else}
    {preload_replace:pre-date_start="{segment_3}-{segment_4}-01"}
{/if}

{exp:calendar:cal 
    date_range_start="{pre-date_start}"
    date_range_end="{segment_3}-{segment_4}-last" 
    dynamic="no" 
    event_limit="3" 
    paginate="bottom" 
    pad_short_weeks="n"}

I'm assuming you're using version 2.9+. If not, use two ifs instead of an if:else.

3
  • You also don't need show_months="" since date_range_end="" should handle that. show_future_entries="" should also be removed: that's unrelated to event entries.
    – Solspace
    Oct 22 '15 at 4:17
  • @Solspace, thanks! You could have edited my answer.
    – Sobral
    Oct 22 '15 at 10:36
  • @ Robson Sobral: You learn something new every day ;) Thanks
    – Solspace
    Oct 28 '15 at 11:59

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.