0

I'm facing another challenge with Solspace Calendar and relationships. I have the usual Events channel and a separate Organisations channel. Entries in the Events channel have a multiple relationships field that allows the event to be related to organisation(s).

As an example, a recurring 'Book Club Meeting' event might be associated with the 'Book Club' entry in the Organisations channel.

Each organisation has its own page on the website and I want to show a list of any upcoming events that are associated to that organisation.

I have tried the below but it shows all events and not just those that are related to the entry I'm looking at. This code doesn't look right to me but I'm not sure what else to try.

{exp:channel:entries channel="organisations" require_entry="yes"}
{parents field="event_organisations" channel="calendar_events" limit="5"}{if parents:count == '1'}<!-- Start Upcoming -->
<section id="upcoming" class="events">
  <div class="hd">
    <h2 class="heading"><a href="/events">Upcoming Meetings &amp; Events</a></h2>
  </div>
  <div class="bd">
    <!-- Start Entry Listing -->
    <ul class="entries">{/if}
      {exp:calendar:events date_range_start="today" show_months="1" pad_short_weeks="n" event_limit="5"}<li class="entry event">
        <h3 class="name"><a href="{path='events/event'}/{if edited_occurrence}{event_parent_id}{if:else}{event_id}{/if}/{event_start_date format="%Y/%m/%d"}">{event_title}</a></h3>
        {if event_all_day}
        <time class="eventdate" datetime="{event_start_date format="%Y-%m-%d"}">{event_start_date format="%j<sup>%S</sup> %F %Y"}</time>
        {if:else}
        <time class="eventdate" datetime="{event_start_date format="%Y-%m-%dT%H:%iZ"}">{event_start_date format="%j<sup>%S</sup> %F %Y <i>at</i> %g:%i%a"}</time>
        {/if}
      </li>{/exp:calendar:events}
    {if parents:count == parents:total_results}</ul>
    <!-- End Entry Listing -->
  </div>
  <div class="ft">
    <a href="/events">See full diary of events</a>
  </div>
</section>
<!-- End Upcoming -->{/if}{/parents}
{/exp:channel:entries}

How can I extract information about events and occurrences based on parent relationships?

2
  • Are you saying that trying to pull related Calendar event entries into this template with the relationships field is causing an error? If so, what is the error it's displaying? (Admin -> System Administration -> Output and Debugging Preferences, set Debug Preference to "2" temporarily if you need to).
    – Solspace
    Commented Jul 26, 2013 at 20:59
  • @Solspace Yes, it only occurs when trying to pull entries from the calendar_events channel. Whatever it is, it's stopping the page from being rendered in the browser. Chrome and Firefox complain about ERR_CONTENT_DECODING_FAILED and Content Encoding Error respectively. It's only occurring when trying to view one of my entries so far - I'm not sure why it's behaving differently. It's a separate issue from my main question though.
    – Matt Obee
    Commented Jul 28, 2013 at 11:19

3 Answers 3

1

Have you tried adding event_name="{parents:url_title}" to the exp:calendar:events tag?

3
  • That causes events to be shown but not their individual occurrences. A step in the right direction perhaps.
    – Matt Obee
    Commented Jul 28, 2013 at 17:44
  • what if you used exp:calendar:occurrences instead of exp:calendar:events?
    – Isabel
    Commented Jul 28, 2013 at 18:02
  • Same result. I've found that exp:calendar:cal combined with your suggestion of parents:url_title shows the next upcoming occurrence of each event with the correct dates. I need to show all upcoming occurrences though.
    – Matt Obee
    Commented Jul 28, 2013 at 18:08
1

I appear to have found a solution to my own problem. I'm not sure if this is the most efficient method, but it certainly seems to work.

I'm calling an embedded template within the channel:entries loop on my Organisation page. Using a parents tag pair, I'm passing the entry_id of each related entry. I've had to include some conditional logic to separate multiple IDs with a pipe character.

{embed="organisations/.org-related-events" 
test_entry_id="{parents field="event_organisations" 
channel="calendar_events" dynamic="off"}
{if parents:count == parents:total_results}{parents:entry_id}{if:else}{parents:entry_id}|{/if}
{/parents}"}

In my embedded template, I'm using exp:calendar:cal to pull out the details of each occurrence. The event_id is pulling through the ID(s) from the embed.

{if embed:test_entry_id ==''}
{if:else}
    <!-- Start Entry Listing -->
    <ul class="entries">
      {exp:calendar:cal event_id="{embed:test_entry_id}" date_range_start="today" show_months="2" pad_short_weeks="n" event_limit="5"}
      <li class="entry event">
        <h3 class="name"><a href="{path='events/event'}/{if edited_occurrence}{event_parent_id}{if:else}{event_id}{/if}/{event_start_date format="%Y/%m/%d"}">{event_title}</a></h3>
        {if event_all_day}
        <time class="eventdate" datetime="{event_start_date format="%Y-%m-%d"}">{event_start_date format="%j<sup>%S</sup> %F %Y"}</time>
        {if:else}
        <time class="eventdate" datetime="{event_start_date format="%Y-%m-%dT%H:%iZ"}">{event_start_date format="%j<sup>%S</sup> %F %Y <i>at</i> %g:%i%a"}</time>
        {/if}
        <p class="description">{event_summary}</p>
        <p class="more"><a href="{path='events/event'}/{if edited_occurrence}{event_parent_id}{if:else}{event_id}{/if}/{event_start_date format="%Y/%m/%d"}">See event details</a></p>
      </li>{/exp:calendar:cal}
    </ul>
    <!-- End Entry Listing -->
{/if}

Now, on my Organisations page, it's showing a list of upcoming occurrences from any and all related events, in chronological order, within the limits I've set.

2
  • Looks like a viable solution. Alternatively, you could have considered adding the relationship field to your "Organizations" channel instead of the "Calendar: Events" channel. Maybe just a personal preference, but sounds like a "cleaner" approach.
    – Solspace
    Commented Jul 31, 2013 at 19:17
  • @Solspace Yeah, that certainly would be another option. The workflow would be a little awkward for my client though (create a new event, then go off and edit the relevant organisation entry and add the relationship back to the event).
    – Matt Obee
    Commented Aug 1, 2013 at 7:53
0

It may not make a difference, but doesn't the parents tag pair also require a channel parameter?

1
  • Only if the same field is used in more than one channel, as far as I know.
    – Matt Obee
    Commented Jul 26, 2013 at 7:57

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.