Hello,
I am using ExpressionEngine v2.7.0 and using the new Relationships Field for the first time. I am trying to conditionally render a block of code if the relationship indeed contains any related entries (as you would using Playa).
I am doing a relationship between Projects and Collaborators. The relationship field lives in the Projects data channel.
This is the code I would hope worked:
{if project_collaborators}
<h4>Collaborators</h4>
<p><ul class="collaborators"><br />
{project_collaborators}<br />
<li>{project_collaborators:title}</li><br />
{/project_collaborators}<br />
</ul><br />
<a href="/collaboration">Learn more</a><br />
{/if}Instead I ended up coding it this way (which works but looks awful):
{project_collaborators}
{if project_collaborators:count == 1}
<h4>Collaborators</h4>
<p><ul class="collaborators"><br />
{/if}<br />
<li>{project_collaborators:title}</li><br />
{if project_collaborators:count == project_collaborators:total_results}<br />
</ul><br />
<a href="/collaboration">Learn more</a><br />
{/if}<br />
{/project_collaborators}This last example isn’t that bad, BUT things get much messier in other more complex instances.
I may be missing something simple so forgive my ignorance. If anyone could advice on how to achieve this it would be greatly appreciated.
Thanks in advance.
Sebastián Jaramillo.