Skip to content
Grav 2.1 is out: every page speaks Markdown. Read the announcement →

Twig loop on nested list

Started by Dan Hart 9 years ago · 2 replies · 1177 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 FrViPofm, 20 hours ago
1 34 7 hours ago
Themes & Styling · by stuart young, 1 month ago
3 480 1 month ago
Themes & Styling · by Sebadamus, 2 months ago
5 481 2 months ago
Themes & Styling · by martynfoster735, 2 months ago
1 460 2 months ago
Themes & Styling · by Justin Young, 2 months ago
1 490 2 months ago