Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more →

Twig loop on nested list

Started by Dan Hart 9 years ago · 2 replies · 1329 views
9 years ago

Hey everyone how would I run a loop on a nested list? For example, lets say I have a parent categories for music genre like "Rock & Roll" , "Country", etc... and then underneath each of those would be artist?

9 years ago

Nest the loops:

TWIG
{% for data as genre %}
  {% for genre as subgenre %}
    {% for subgrense as artist %}
      {{ artist.name }}
    {% endfor %}
  {% endfor %}
{% endfor %}
👍 1
9 years ago

Thanks OleVik!

When I first started to work through this I only had 2 "for" loops but it turned out I needed 3 like what you have here. Worked like a charm, thanks!

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by MarkP, 7 days ago
3 123 3 days ago
Themes & Styling · by TomW, 6 days ago
0 67 6 days ago
Themes & Styling · by themetman, 2 weeks ago
1 159 2 weeks ago
Themes & Styling · by AH, 4 weeks ago
1 274 2 weeks ago
Themes & Styling · by Bruno, 4 years ago
6 1462 2 weeks ago