I have an unusual layout that requires formatting images 3 different ways for each 3 images. Then I need to repeat that set - if more images exist. I have a clunky way to start it now but wondered if there was a cleaner way to do it. Here's what I have so far:
{# set 1 #}
<div class="flexItem">
{% for image in entry.gallery.limit(1).all() %}
<img class="unique1" src="{{ image.url }}">
{% endfor %}
<div class="flexRight">
{% for image in entry.gallery.limit(1).offset(1).all() %}
<img class="unique2" src="{{ image2.url }}">
{% endfor %}
{% for image in entry.gallery.limit(1).offset(2).all() %}
<img class="unique3" src="{{ image3.url }}">
{% endfor %}
</div>
</div>
{# set 2 if more images exist #}
<div class="flexItem">
{% for image in entry.gallery.limit(1).offset(4).all() %}
<img class="unique1" src="{{ image.url }}">
{% endfor %}
<div class="flexRight">
{% for image in entry.gallery.limit(1).offset(5).all() %}
<img class="unique2" src="{{ image2.url }}">
{% endfor %}
{% for image in entry.gallery.limit(1).offset(6).all() %}
<img class="unique3" src="{{ image3.url }}">
{% endfor %}
</div>
</div>
One final thing need is put a conditional in to test if an image exists. Right now, if an image doesn't exist the layout gets broken. I assume because the last loop doesn't fire to close the html. Tried using {% if image | length %}
{% endif %} but that doesn't seem to work.
– glider Feb 09 '23 at 14:28loop.lastto check if you're on the last item in the row, I've updated my answer with an example. If this solves your issue, please remember to mark the answer as accepted. Thanks! – MoritzLost Feb 09 '23 at 17:36