I have the following code:
{staff_member_groups}
<h2>{staff_member_groups:staff_group_heading}</h2>
<ul class="staff_member_groups">
{staff_member_groups:staff_group_members}
<li class="{switch='odd|even'}">
<img src="{staff_member_groups:staff_group_members:staff_portrait}">
<h3>{staff_member_groups:staff_group_members:title}</h3>
<p class="meta">
{staff_member_groups:staff_group_members:staff_position}
</p>
<p>
{staff_member_groups:staff_group_members:staff_titles}
</p>
</li>
{/staff_member_groups:staff_group_members}
</ul>
{/staff_member_groups}
which renders correctly except for the fact that {switch='odd|even'}
returns odd
on every list item. Is there a way to get this functionality while looping through a relationship tag?
Edit: I should clarify: {staff_member_groups}
is a grid field, with {staff_member_groups:staff_group_members}
being the relationship field within the grid field.
Edit #2: I’ve found the solution (still new around here, SE won’t let me answer my own questions really quickly yet). {switch='odd|even'}
needs to be namespaced so that it switches within the context of the relationship field, like so: {staff_member_groups:staff_group_members:switch='odd|even'}
. Otherwise, {switch='odd|even'}
is going by the larger context of the entries tag that surrounds this template.
For clarity, my final block of code looks like this:
{staff_member_groups}
<h2>{staff_member_groups:staff_group_heading}</h2>
<ul class="staff_member_groups">
{staff_member_groups:staff_group_members}
<li class="{staff_member_groups:staff_group_members:switch='odd|even'}">
<img src="{staff_member_groups:staff_group_members:staff_portrait}">
<h3>{staff_member_groups:staff_group_members:title}</h3>
<p class="meta">
{staff_member_groups:staff_group_members:staff_position}
</p>
<p>
{staff_member_groups:staff_group_members:staff_titles}
</p>
</li>
{/staff_member_groups:staff_group_members}
</ul>
{/staff_member_groups}