1

Using Solspace Calendar, I am displaying a list of related entries (from a relationship field) on an individual event page, like so:

{exp:calendar:events event_id="{embed:event_id}"}
<section id="related-orgs">
<div class="hd">
    <h2>Related Organisations</h2>
</div>
<div class="bd">
    <!-- Start Entry Listing -->
    <ul class="entries compact">
        {event_organisations}<li class="entry"><a href="#">{event_organisations:title}</a></li>{/event_organisations}
     </ul>
    <!-- End Entry Listing -->
</div>
</section>
{/exp:calendar:events}

This is pulling through the related entries correctly.

However, if there are no related entries, I don't want that section to appear at all. I have tried using count and total_results as per the below, but this appears to prevent it from showing even when there are relationships.

{exp:calendar:events event_id="{embed:event_id}"}
{if event_organisations:count == "1"}<section id="related-orgs">
<div class="hd">
    <h2>Related Organisations</h2>
</div>
<div class="bd">
    <!-- Start Entry Listing -->
    <ul class="entries compact">{/if}
        {event_organisations}<li class="entry"><a href="#">{event_organisations:title}</a></li>{/event_organisations}
     {if event_organisations:count == event_organisations:total_results}</ul>
    <!-- End Entry Listing -->
</div>
</section>{/if}

Am I missing an obvious solution?

1

Since you don't need to show calendar data in this part of template, why not to use the traditional channel:entries module?

Plus, you're checking for the position in the loop outside the loop!

{exp:channel:entries entry_id="{embed:event_id}"}
    {event_organisations}
    {if event_organisations:count == 1}
        <section id="related-orgs">
            <div class="hd">
                <h2>Related Organisations</h2>
            </div>
            <div class="bd">
                <!-- Start Entry Listing -->
                <ul class="entries compact">
    {/if}
                    <li class="entry"><a href="#">{event_organisations:title}</a></li>
    {if event_organisations:count == event_organisations:total_results}
                </ul>
            <!-- End Entry Listing -->
            </div>
        </section>
    {/if}
    {/event_organisations}
{/exp:channel:entries}
2
  • Interesting idea. I've tried it but the section doesn't appear at all when using channel:entries, even when there are relationships to show. – Matt Obee Jul 19 '13 at 18:16
  • Of course! Eureka! Our code is completely wrong. I gonna fix it! – Sobral Jul 19 '13 at 18:22

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.