0

I have a Playa relationship between my "News" and "Projects" channels. In a News entry, you can select a related Project, so "News" is the parent and "Projects" is the child.

I have the following code on my Project template, and it works correctly to show related News items. However, I would like to hide the entire section when there are no related News items. I thought perhaps wrapping the section with {if no_parents}{if:else}...{/if} would work, but I believe this type of statement must reside within the {exp:playa:parents ... } tag pair.

{!-- TO DO: put in logic to hide block if no related news --}
<!-- Sidebar Related News -->
<h4>Related News</h4>
<ul>
    {exp:playa:parents channel="News"}
    <li><a href="{page_url}">{title}</a></li>
    {/exp:playa:parents}
</ul>
<!-- Sidebar Related News::END -->

Is there something simple here I'm overlooking?

I am using ExpressionEngine version 2.5.3 and Playa version 4.4.2.

Thanks!

1 Answer 1

6

You can do this:

{exp:playa:parents channel="News"}

  {if count == 1}
    <h4>Related News</h4>
    <ul>
  {/if}

      <li><a href="{page_url}">{title}</a></li>

  {if count == total_results}
    </ul>
  {/if}

{/exp:playa:parents}
0

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.