Using a loop in a loop, how do I check if child loop is empty to not display parent loop? 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 %}

        &lt;div&gt;
            &lt;h3&gt;{{ letter | upper }}&lt;/h3&gt;
            &lt;ul&gt; 
            {% for entry in letterEntries %}
                {% if entry.intoCollection %}
                    &lt;li&gt;&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/li&gt;
                {% endif %}
            {% endfor %}
            &lt;/ul&gt;
        &lt;/div&gt;

        {% endif %}
    {% endfor %}

{% endfor %}


It displays letters duplicated, but also letters that contain no names...

Any idea? Thanks!
You'd further filter your returned artist entries down like this:

{% set artists = craft.entries.section('artists').intoCollection('1') %}


Then remove all the unnecessary "intoCollection" conditionals in your loop.