My use case is as follows: For a particular episode, I have a contributor who does both editing and presenting.
I have now added the contributor twice, once for each role. So far, I use a {% for contributor in episode.contributors %} loop, which of course ends up giving me the contributor twice. This looks too cluttered, especially with more roles I would like to add. This leads me to my questions:
For a particular episode, is there a way to store multiple roles for a particular contributor without adding the contributor twice, three times etc.?
Alternatively, if the contributor is stored twice (once with the role “editor” and once with the role “presenter”), is there a way to elegantly extract/present all the roles of a particular person with the template language? I would be grateful for a tip to get a result looking something like this:
You can’t store multiple roles per entry (intentionally).
It’s possible to reduce the data to show contributors which each assigned role using Podlove Templates. But I don’t have a solution handy right now, maybe @ericteubert can give you a hint?
Correct, the only way to do it is to add the same contributor multiple times with different roles. To make this work in Twig is a bit cumbersome but possible. This template works:
{# remember which contributors we printed already so we won't have duplicates #}
{% set contributorsDone = [] %}
<ul>
{% for contributor in episode.contributors %}
{# skip if we printed this contributor already #}
{% if not (contributor.name in contributorsDone) %}
{# loop over all contributors and remember all roles for current contributor #}
{% set roles = [] %}
{% for c in episode.contributors %}
{% if c.name == contributor.name %}
{% set roles = roles|merge([c.role]) %}
{% endif %}
{% endfor %}
{# mark this contributor as done #}
{% set contributorsDone = contributorsDone|merge([contributor.name]) %}
<li>
{{ contributor.name }} ({{ roles|join(", ") }})
</li>
{% endif %}
{% endfor %}
</ul>
Yes And I would venture to argue that it solves at least 90% of use cases. Assigning a single role or just the main role is enough for most. As far as I can remember, you are the first one asking for multiple assignments