<p>The simplest way is to create a "filtered" array, containing the unique cables, and then loop through that.</p>

<p>For example:</p>

<pre><code>{# Build the "filtered" array of cables #}
{% set filteredCables = [] %}

{% for row in entry.tests %}
    {% for cable in row.cables %}
        {% if cable.title not in filteredCables %}
            {% set filteredCables = filteredCables|merge([cable.title]) %}
        {% endif %}
    {% endfor %}
{% endfor %}

{# Output the unique cables #}
{% for cable in filteredCables %}
    {{ cable }}&lt;br /&gt;
{% endfor %}
</code></pre>

CC BY-SA 3.0
2017-03-21T16:34:21.937Z
Thanks for this @StephenLewis - I had actually tried this as I picked it up from another stack exchange post. However, I keep hitting them same error; Variable "filteredCables" does not exist.

I have tried to set the {% set filteredCables = [] %} before I then set it in the loop but it still seems to output all the cables (duplicates) and not a filtered list. Any ideas?
Terry Upton
CC BY-SA 3.0
2017-03-21T16:37:06.503Z
Regarding the variable does not exist error, you could do this: `{% set filteredCables = filteredCables|default([])merge([cable]) %}`. As for it not outputting a filtered list, have you tried just adding the titles? For example: `{% if cable.title not in filteredCables %}{% set filteredCables = filteredCables|default([])|merge([cable]) %}{% endif %}`
Stephen Lewis
CC BY-SA 3.0
2017-03-21T17:17:16.117Z
Thanks Stephen - the problem was solved by setting cable.title. I had to add an empty variable at the start outside the loop too {% set filteredCables = [] %}. Thanks for putting me in the right direction.
Terry Upton
CC BY-SA 3.0
2017-03-21T17:31:23.313Z
Glad you got it sorted. I've updated the answer to use the cable title.
Stephen Lewis
CC BY-SA 3.0
2017-03-21T16:26:49.293Z
2017-03-21T17:30:55.120Z
2017-03-21T17:30:55.120Z
Stephen Lewis
<p>Anyone able to assist me with removing duplicates in this example?
So I have a related entries (cables) setup in a SuperTable. Some of these entries are duplicated across different rows. So a cable might be related to the first row in the SuperTable and also row3 and row4.</p>

<p>I want to be able to run through all these cables in any SuperTable row and output the entries just once not duplicated.
So as an example a basic SuperTable setup like this;</p>

<pre><code>{% for row in entry.tests %}
    {% for cable in row.cables %}
        {{ cable.title }}&lt;br /&gt;
    {% endfor %}
{% endfor %}
</code></pre>

<p>would output this;<br>
BS 7211<br>
BS EN 50525<br>
BS 6724<br>
BS 8573<br>
BS 7835<br>
BS 7629-1<br>
BS 8436<br>
BS 5467<br>
BS 6724<br>
BS 7846<br>
BS 6622<br>
BS 7835  </p>

<p>I want to essentially loop through and only display the related entry once. As you can see from the example some entries are duplicated (e.g BS 6724)</p>

<relations><array><plugin-supertable>
Remove duplicated entries from SuperTable related entries
# Remove duplicated entries from SuperTable related entries

(Asked by: username_0 on 2017-03-21)

Anyone able to assist me with removing duplicates in this example?
So I have a related entries (cables) setup in a SuperTable. Some of these entries are duplicated across different rows. So a cable might be related to the first row in the SuperTable and also row3 and row4.
I want to be able to run through all these cables in any SuperTable row and output the entries just once not duplicated.
So as an example a basic SuperTable setup like this;
{% for row in entry.tests %}
    {% for cable in row.cables %}
        {{ cable.title }}
    {% endfor %}
{% endfor %}

would output this;
BS 7211
BS EN 50525
BS 6724
BS 8573
BS 7835
BS 7629-1
BS 8436
BS 5467
BS 6724
BS 7846
BS 6622
BS 7835  
I want to essentially loop through and only display the related entry once. As you can see from the example some entries are duplicated (e.g BS 6724)

**Tags:** relations, array, plugin-supertable

---

## 1 answers

### Answer by username_1 on 2017-03-21. Score: 2 | Accepted answer

The simplest way is to create a "filtered" array, containing the unique cables, and then loop through that.
For example:
{# Build the "filtered" array of cables #}
{% set filteredCables = [] %}

{% for row in entry.tests %}
    {% for cable in row.cables %}
        {% if cable.title not in filteredCables %}
            {% set filteredCables = filteredCables|merge([cable.title]) %}
        {% endif %}
    {% endfor %}
{% endfor %}

{# Output the unique cables #}
{% for cable in filteredCables %}
    {{ cable }}
{% endfor %}

> **Comments:**
> **username_0**: Thanks for this @StephenLewis - I had actually tried this as I picked it up from another stack exchange post. However, I keep hitting them same error; Variable "filteredCables" does not exist.  I have tried to set the {% set filteredCables = [] %} before I then set it in the loop but it still seems to output all the cables (duplicates) and not a filtered list. Any ideas?  
> **username_1**: Regarding the variable does not exist error, you could do this: `{% set filteredCables = filteredCables|default([])merge([cable]) %}`. As for it not outputting a filtered list, have you tried just adding the titles? For example: `{% if cable.title not in filteredCables %}{% set filteredCables = filteredCables|default([])|merge([cable]) %}{% endif %}`  
> **username_0**: Thanks Stephen - the problem was solved by setting cable.title. I had to add an empty variable at the start outside the loop too {% set filteredCables = [] %}. Thanks for putting me in the right direction.  
> **username_1**: Glad you got it sorted. I've updated the answer to use the cable title.  

---

