2

While using Solspace Calendar I'm trying to limit recurrent events to only the next occurrence. I found a great tip on how to do it with PHP here: Solspace Calendar: Only show next occurrence of recurring event in list of recurring and non-recurring events

Here's a trimmed down version of what I'm currently trying:

{embed="_layouts/index"}
{exp:calendar:cal date_range_start="today" show_months="4" pad_short_weeks="n"}
      {exp:stash:append_list name="events-list" parse_tags="yes"}
        {stash:item_entry_id}{entry_id}{/stash:item_entry_id}
      {/exp:stash:append_list}
    {/exp:calendar:cal}

{exp:stash:get_list name="events-list"}
  {exp:calendar:cal event_id="{item_entry_id}" event_limit="1"}
    {exp:stash:set_list name="events-show"}
      {stash:the_title}{title}{/stash:the_title}
    {/exp:stash:set_list}
  {/exp:calendar:cal}
{/exp:stash:get_list}

{exp:stash:set name="content"}
  {exp:stash:get_list name="events-show"}
    <h4>{the_title}</h4>
  {/exp:stash:get_list}
{/exp:stash:set}

Content is then pulled into my template.

I'm given no output but even if it did my logic is clearly off. Hitting the database this much is really bad.

Any suggestions?

1 Answer 1

1

Going back through the stash documentation provided the answer I needed! The unique parameter on get_list was the missing piece to the puzzle. Below is a refactored version of the code, which now hits the database far less.

{embed="_layouts/index"}

    {exp:calendar:cal date_range_start="today" show_months="4" pad_short_weeks="n"}
      {exp:stash:append_list name="events-list" parse_tags="yes"}
        {stash:item_entry_id}{entry_id}{/stash:item_entry_id}
        {stash:the_title}{title}{/stash:the_title}
      {/exp:stash:append_list}
    {/exp:calendar:cal}

    {exp:stash:set name="content"}
      {exp:stash:get_list name="events-list" unique="item_entry_id"}
        <h4>{the_title}</h4>
      {/exp:stash:get_list}
    {/exp:stash:set}

Hopefully that helps someone else struggling with the logic of using Stash and Solspace Calendar to pull off something similar.

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.