CMS Development

ben-duchy
Contributeur de premier rang

Create a loop inside another loop

Résolue

I have a large HubDB database with many repeating entries within the same column. Is it possible to show only 1 of any repeating row? I've tried using an if condition to show the first of the loop, but this only shows the first of the whole master loop, instead of removing any repeating ones.

 

For example, imagine a car database with 10 rows, but only 5 manufactures, meaning there's 2 rows each. Is there a way to loop them all in 1 list, but only show the 5 different manufactures, not all 10 rows? 

0 Votes
1 Solution acceptée
Brownstephen101
Solution
Contributeur de premier rang | Partenaire solutions Elite
Contributeur de premier rang | Partenaire solutions Elite

Create a loop inside another loop

Résolue

@ben-duchy 
You'll need to loop through your rows and check if they row exists in a variable, then loop through the new list that's created, for example:

{% set cars = [] %}
{% for item in rows %}
{% unless item in cars %}
{% do cars.append( item ) %}
{% endunless %}
{% endfor %}

{% for loop in cars %}
{# Your loop #}
{% endfor %}


Hope that helps.

Voir la solution dans l'envoi d'origine

2 Réponses
ben-duchy
Contributeur de premier rang

Create a loop inside another loop

Résolue

Thanks @Brownstephen101 I'll give that a try.

Brownstephen101
Solution
Contributeur de premier rang | Partenaire solutions Elite
Contributeur de premier rang | Partenaire solutions Elite

Create a loop inside another loop

Résolue

@ben-duchy 
You'll need to loop through your rows and check if they row exists in a variable, then loop through the new list that's created, for example:

{% set cars = [] %}
{% for item in rows %}
{% unless item in cars %}
{% do cars.append( item ) %}
{% endunless %}
{% endfor %}

{% for loop in cars %}
{# Your loop #}
{% endfor %}


Hope that helps.