<p>The issue is: you don't really loop your entries at all.</p>

<pre class="lang-TWIG prettyprint-override"><code>{# get all super table rows #}
{% set superTableRows = block.related.all %}

{% if superTableRows is not empty %}
    &lt;div class="{{ padding }} {{ fontsize }}" id="{{ blockID }}"&gt;
        &lt;div class="{{ margin }}"&gt;

            {# loop all of your super tables #}
            {% for row in superTableRows %}

                {# loop all contentEntries in each row #}
                {% for entry in row.contentEntry.all() %}

                    {# 
                        display the alternative title set in your supertablerow 
                        and if thats not set display the entries title
                    #}
                    {{ row.altTitle?? entry.title }}

                    {# same as above #}
                    {{ row.altDescription ?? entry.previewDescription }}

                {% endfor %}
            {% endfor %}
        &lt;/div&gt;
    &lt;/div&gt;
{% endif %}
</code></pre>

<p><code>block.related</code> is an Object of type <code>ElementQuery</code>. <code>block.related.altDescription</code> returns the criteria of this Query, this is mostly empty since no criteria is set by default. </p>

CC BY-SA 4.0
2019-03-21T09:22:55.640Z
Thanks Robin! superTables should be superTableRows in this example.
Dan Lee
CC BY-SA 4.0
2019-03-21T09:24:06.497Z
Uh yeah copy paste fail. Does it work for you?
Robin Schambach
CC BY-SA 4.0
2019-03-21T09:27:05.037Z
Yes, this is working well! Some coding efficiency in there too which is appreciated as a learning point.
Dan Lee
CC BY-SA 4.0
2019-03-20T19:19:05.823Z
2019-03-21T09:23:39.330Z
2019-03-21T09:23:39.330Z
Robin Schambach
<p>I need to loop related entries. </p>

<p>I am using a SuperTable field with the handle "related" with an entry field with the handle "contentEntry" and two text fields for alternative text and descriptions.</p>

<p>The "contentEntry" field is limited to two entries being selected. The issue I'm having is that the following code repeats the first entry twice and doesn't loop and display the second. What am I doing wrong?</p>

<pre><code>{# Related Entry #}

{% set relatedEntries = block.related.all %}
{% set relatedEntry = block.related.contentEntry.all() %}
{% set relatedAltDesc = block.related.altDescription %}
{% set relatedAltTitle = block.related.altTitle %}


{% if relatedEntries %}

&lt;div class="{{ padding }} {{ fontsize }}" id="{{ blockID }}"&gt;
    &lt;div class="{{ margin }}"&gt;

            {% for entries in relatedEntries %}

              {% for rel in relatedEntry %}

                {% if relatedAltTitle %}
                  {{ relatedAltTitle }}
                {% else %}
                  {{ rel.title }}
                {% endif %}


                {% if relatedAltDesc %}
                  {{ relatedAltDesc }}
                {% else %}
                  {{ rel.previewDescription }}
                {% endif %}

              {% endfor %}

            {% endfor %}

    &lt;/div&gt;
&lt;/div&gt;

{% endif %}
</code></pre>

<p><a href="https://i.sstatic.net/jEZ66.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/jEZ66.png" alt="enter image description here"></a></p>

<templating><forloop><plugin-supertable>
Looping Related Entries with a Super Table
# Looping Related Entries with a Super Table

(Asked by: username_0 on 2019-03-20)

I need to loop related entries. 
I am using a SuperTable field with the handle "related" with an entry field with the handle "contentEntry" and two text fields for alternative text and descriptions.
The "contentEntry" field is limited to two entries being selected. The issue I'm having is that the following code repeats the first entry twice and doesn't loop and display the second. What am I doing wrong?
{# Related Entry #}

{% set relatedEntries = block.related.all %}
{% set relatedEntry = block.related.contentEntry.all() %}
{% set relatedAltDesc = block.related.altDescription %}
{% set relatedAltTitle = block.related.altTitle %}


{% if relatedEntries %}


    

            {% for entries in relatedEntries %}

              {% for rel in relatedEntry %}

                {% if relatedAltTitle %}
                  {{ relatedAltTitle }}
                {% else %}
                  {{ rel.title }}
                {% endif %}


                {% if relatedAltDesc %}
                  {{ relatedAltDesc }}
                {% else %}
                  {{ rel.previewDescription }}
                {% endif %}

              {% endfor %}

            {% endfor %}

    


{% endif %}

**Tags:** templating, forloop, plugin-supertable


---

## 1 answers

### Answer by username_1 on 2019-03-20. Score: 2 | Accepted answer

The issue is: you don't really loop your entries at all.
{# get all super table rows #}
{% set superTableRows = block.related.all %}

{% if superTableRows is not empty %}
    
        

            {# loop all of your super tables #}
            {% for row in superTableRows %}

                {# loop all contentEntries in each row #}
                {% for entry in row.contentEntry.all() %}

                    {# 
                        display the alternative title set in your supertablerow 
                        and if thats not set display the entries title
                    #}
                    {{ row.altTitle?? entry.title }}

                    {# same as above #}
                    {{ row.altDescription ?? entry.previewDescription }}

                {% endfor %}
            {% endfor %}
        
    
{% endif %}

block.related is an Object of type ElementQuery. block.related.altDescription returns the criteria of this Query, this is mostly empty since no criteria is set by default.

> **Comments:**
> **username_0**: Thanks Robin! superTables should be superTableRows in this example.  
> **username_1**: Uh yeah copy paste fail. Does it work for you?  
> **username_0**: Yes, this is working well! Some coding efficiency in there too which is appreciated as a learning point.  

---

