I'm trying to display a list of names alphabetically ordered. This is working fine, but I also want to check if the name is intoCollection or not (using a Lightswitch).
If it is intoCollection, it displays the letter + the list of names related. If there is no name related to the letter, I need to display nothing (= no letter).
Here is the code which seems good for me, but is not correct:
{% set artists = craft.entries.section('artists').limit(null).order('title') %}
{% for letter, letterEntries in artists | group('title|upper|slice(0, 1)') %}
{% for entry in letterEntries %}
{% if entry.intoCollection | length %}
<div>
<h3>{{ letter | upper }}</h3>
<ul>
{% for entry in letterEntries %}
{% if entry.intoCollection %}
<li><a href="{{ entry.url }}">{{ entry.title }}</a></li>
{% endif %}
{% endfor %}
</ul>
</div>
{% endif %}
{% endfor %}
{% endfor %}
It displays letters duplicated, but also letters that contain no names...
Any idea? Thanks!