6

I am needing to display a list of Calendar events that are selected from a Playa field. Of course, I need it to not display events that has passed (by event date) and if the events in the Playa custom field are all passed a 'No Events' message is returned.

My setup is as follows: Channel A contains the Playa custom field that is pulling in all Event entries.

My code is below:


{exp:channel:entries channel="education" disable="categories|member_data|pagination"}
<ul> 
  {exp:playa:children channel="calendar_events" limit="5"}
    {exp:calendar:events event_id="{entry_id}" date_range_start="today" date_range_end="3 months"}
      {if calendar_no_results}
      No Events
      {/if}
      <li>{title}</li>                    
    {/exp:calendar:events}
  {/exp:playa:children}
</ul>
{/exp:channel:entries}


Doing this sort of works as it will output 'No Events' but it will do it twice as there are two entries selected in the Playa field that have passed.

If a event that hasn't passed (schedule for next month) that list will display the future event along with the 2 'No Events' for the other 2 passed events.

I've messed with Stash as well trying the calendar:events tag for the append_list and placing the get_list within channel and playa tags; see below.


{exp:calendar:events event_id="{entry_id}" date_range_start="today" date_range_end="3 months"}
{exp:stash:append_list name="cal_events"}
  {stash:item_title}{title}{if calendar_no_results}No Events{/if}{/stash:item_title}
{/exp:stash:append_list}
{/exp:calendar:events}

{exp:channel:entries channel="education" disable="categories|member_data|pagination"} 
<ul class="icons-ul">
{exp:playa:children channel="calendar_events"}
  {exp:stash:get_list name="cal_events" limit="5"}
  <li>{item_title}</li>
  {/exp:stash:get_list}
</ul>
{/exp:channel:entries}

what am i missing?

thanks in advance!

2
  • Did any of these answers work out for you, Tad?
    – Alex Kendrick
    Nov 12, 2013 at 22:43
  • None of the answers worked. I did however simplify it and make have event event under 1 of 3 categories which matches the name of the channel (i.e. Channel A).
    – Tad Ward
    Nov 13, 2013 at 1:45

3 Answers 3

2
+100

I've done this before with NSM Transplant. But I've been slowly removing it in favor of Stash. This question inspired me to finish the process with this template, so thank you!

First off, I think there might be a workflow problem with your question. I'm not sure how often people will be updating events but from what it sounds like is that when someone wants to add a new event, after publishing it they have to go back and edit Channel A to associate that event with the channel. I've found that for adding new events it's better that the Playa field is in the event itself. That way, adding an event only requires publishing a new entry that way, rather than publishing a new entry and editing a previous one.

You very well might have reason you've set it up that way. So my answer assumes your current workflow is correct.

First off, we need to get the event ids from the playa field, as in Stephen's answer. Some differences: I use the playa:children_ids tag here which is perfect for stuff like this.

Second, you can't put a limit on this tag, but you really wouldn't want to. What if the first five found by playa were all expired Calendar Entries? There could be 20 others that are not expired and wouldn't show up. Best to leave the limiting to the Calendar tag itself.

{exp:stash:set name="eventids" parse_tags="yes" parse_depth="2"}
    {exp:channel:entries channel="education" disable="categories|member_data|pagination"}
        {exp:playa:children_ids channel="calendar_events"}
    {/exp:channel:entries}
{/exp:stash:set}

Next, I used Switchee myself instead of two if statements Stephen used. It gives me the chance to verify the data I got from playa was accurate with a regex statement.

In the Calendar:Cal tag is where I limit my returned events, since now we have all the potential events and not just the first five that could be expired Calendar Events.

{exp:switchee variable="stash:eventids" parse="inward"}
    {case value="#([0-9]+\&#124;?)+#"}
        {exp:stash:set name="actualdata" parse_tags="yes" parse_depth="4"}
            {exp:calendar:cal event_id="{stash:eventids}" sort="asc" date_range_start="today"  show_months="3" pad_short_weeks="n" event_limit="5"}
                {if event_count == 1}<ul>{/if}
                    <li>{title}</li>
                {if event_total == "{event_count}"}</ul>{/if}
                {if calendar_no_results}
                    No Events
                {/if}
            {/exp:calendar:cal}
        {/exp:stash:set}
    {/case}
    {case value=""}
        {exp:stash:set name="actualdata"}
            No Events
        {/exp:stash:set}
    {/case}
{/exp:switchee}

Then you just stash:get your actualdata for whereever you stash:set your main content for your wrapper template.

If what I described to you with the workflow being off makes sense, this all still works with one slight change. You just have to change the children_ids to parent_ids once you put the Playa tag in the Calendar Events channel.

1
  • I tried this but nothing output. I will continue to mess with this answer to see what I can come up with. Appreciate it.
    – Tad Ward
    Nov 13, 2013 at 1:44
3

Try capturing the entry_ids to set a stash value then use that value to define the calendars tag.

Grab the entry_ids for the events.

{exp:stash:set parse_tags="yes"}
  {exp:channel:entries channel="education" disable="categories|member_data|pagination"}
    {stash:event_ids}0{exp:playa:children channel="calendar_events" limit="5"}|{entry_id}{/exp:playa:children}{/stash:event_ids}
  {/exp:channel:entries}
{/exp:stash:set}

{stash:event_ids} should output something like 0|32|54|73 which you can now use in your calendar tag pair.

{if "{stash:event_ids}" == ""}No Events{/if} {-- you may be able to remove the quote and brackets from the stash:event_ids tag --}
{if "{stash:event_ids}" != ""}
  <ul>
    {exp:calendar:events event_id="{stash:event_ids}" date_range_start="today" date_range_end="3 months"}
      <li>{title}</li>
    {/exp:calendar:events}
  </ul>
{/if}

The only thing I don't remember is if the date_range_ parameters will override the event_id parameter.

UPDATE

You said the above didn't offer a way to display "No Events" if there were expired events in the Playa list of entry_ids. You should be able to apply {if calendar_no_results}{/if} using the exp:calendar:cal tag with date ranges. See below.

{if "{stash:event_ids}" == ""}No Events{/if} {-- you may be able to remove the quote and brackets from the stash:event_ids tag --}
{if "{stash:event_ids}" != ""}
  {exp:calendar:cal event_id="{stash:event_ids}" date_range_start="today" date_range_end="3 months"}
    {if calendar_no_results}No Events{/if} 
    {if event_count == 1}<ul>{/if}
      <li>{title}</li>
    {if event_total == "{event_count}"}</ul>{/if}
  {/exp:calendar:cal}
{/if}
5
  • 1
    May I add that if you're looking to display something like "upcoming events", i.e. events based on a timeframe, you should be using {exp:calendar:cal}, not {exp:calendar:events}. A longer explanation on why {exp:calendar:cal} is the accurate tag to use in those cases can be found in the Solspace Documentation
    – Solspace
    Oct 22, 2013 at 19:37
  • both cal and events tag both produce the same outcome with what I am trying to accomplish. I am displaying a list of events (Channel B) that are related to Channel A via a Playa field. This works but need it to say 'No Events' if the related events in the Playa field are all passed or no future events in field at all. Adding the {if_calendar_no_results} or {if no_results} conditional to events and cal tags respectively produces a 'No Events' message but if any passed events are in Playa field, it displays the 'No Events' message equal to number of passed events/entries in the Playa field.
    – Tad Ward
    Oct 23, 2013 at 1:39
  • I added an element above for you. Nov 6, 2013 at 9:58
  • will try this out later today. thank you!
    – Tad Ward
    Nov 7, 2013 at 17:16
  • i wasn't able to get this to work. as the 'No Events' portion didn't show. thanks.
    – Tad Ward
    Nov 13, 2013 at 1:42
1

I can't locally test this, but I thought if you could use some time of looping/increment plugin you could potentially use a couple conditionals to test and increment within the {calendar_no_results} tag. I was thinking this could work with the Loop Plus add-on:

{exp:channel:entries channel="education" disable="categories|member_data|pagination"}
<ul> 
  {exp:playa:children channel="calendar_events" limit="5"}
    {exp:calendar:events event_id="{entry_id}" date_range_start="today" date_range_end="3 months"}
      {exp:loop_plus start="1" increment="1"}
          {if calendar_no_results}

                {loop_area}
                    {loop_count}
                {/loop_area}

          {/if}

          <li>{title}</li> 

          {if count == total_results AND loop_count > 1}
            No Events?
          {/if}

      {/exp:loop_plus}                  
    {/exp:calendar:events}
  {/exp:playa:children}
</ul>
{/exp:channel:entries}
2
  • will try this out later today. thank you!
    – Tad Ward
    Nov 7, 2013 at 17:16
  • couldn't get it to work. The 'No Events' portion didn't show. Thanks.
    – Tad Ward
    Nov 13, 2013 at 1:43

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.