For loop in another for loop

 <div class="card-group transp">
  {% for mainsubject in page.header.mainsubjects %}
  <div class="card transp">
    <div class="card-block">
      <h4 class="card-title">{{ mainsubject.title }}</h4>
      <p class="card-text">{{ mainsubject.text }}</p>
      <ul class="list-group list-group-flush">
        {% for link in page.header.mainsubjects.links %}
        <li class="list-group-item transp"><a href="{{ link.title }}" class="card-link">{{ link.title }}</a></li>
        {% endfor %}
      </ul>
    </div>
  </div>
  {% endfor %}
</div>

Frontmatter:

mainsubjects:
    -
         title: title
         text: test
         links:
            -
                title: test
                link: http://www.test.com
            -
                title: test
                link: http://www.test.com
    -
         title: title
         text: test
         links:
            -
                title: test
                link: http://www.test.com
            -
                title: test
                link: http://www.test.com

Hi! Cannot get the link to list within each mainsubject. The first for loop works good, just not the for loop inside…

Appriciate all help!

Thanks!

1 Like

Hi
I’ve done something similar but can’t seem to find my example so kinda just thinking out loud here but I think you can use the first loop for the second loop- something like
{% for link in mainsubject.links %}
because I think as it is you’ll get all 4 links coming through at once - no?

1 Like

Wow! Thank you very much! I did think of the option it would read directly through the first loop :slight_smile: haha so happy! This is much simpler then i expected!
This works great! So you are right, if you create a loop of any data set then the loop of datasets inside that would not need where to go other then the second loop.

   <div class="card-group transp">
  {% for mainsubject in page.header.mainsubjects %}
  <div class="card transp">
    <div class="card-block">
      <h4 class="card-title">{{ mainsubject.title }}</h4>
      <p class="card-text">{{ mainsubject.text }}</p>
      <ul class="list-group list-group-flush">
        {% for link in mainsubject.links %}
        <li class="list-group-item transp"><a href="{{ link.title }}" class="card-link">{{ link.title }}</a></li>
        {% endfor %}
      </ul>
    </div>
  </div>
  {% endfor %}
</div>

Thank you again!