Reputation: 222
How can I have a nested loop and then carry on from the previous loop?
Example:
{% for image in site_images[page.id].images %}
<div class="container">
<div class="item">
<img src="{{ image[loop.index0] }}" />
<img src="{{ image[loop.index0] }}" />
<img src="{{ image[loop.index0] }}" />
<img src="{{ image[loop.index0] }}" />
</div>
</div>
<div class="container">
<div class="item">
<img src="{{ image[loop.index0] }}" />
<img src="{{ image[loop.index0] }}" />
<img src="{{ image[loop.index0] }}" />
<img src="{{ image[loop.index0] }}" />
</div>
</div>
....
{% endfor %}
How can I make it show 4 images in the first .container > .item div
, then come out create a new .container > .item div
and carry on so it would be image[4]
Upvotes: 2
Views: 987
Reputation: 52513
You can use the batch
filter:
{% for section in images|batch(4) %}
<div class="container">
<div class="item">
{% for image in section %}
<img src="{{ image }}" />
{% endfor %}
</div>
</div>
{% endfor %}
Upvotes: 4