1

My problem is this: I want to build a grid with two items each row. The following loop works perfect with even numbers of items like 2,4,6,... because the grid closes correctly with a </div><!-- /.row -->.

{% for image in page.image %}
    {% cycle '<div class="row">', '' %}
        <div class="large-6 columns">{% image bigthumb {{ image }} class="th" %}</div><!-- /.large-6.columns -->
    {% cycle '', '</div><!-- /.row -->' %}
{% endfor %}

But if I have an odd/uneven number of items my grid won't get its necessary closing </div>. How can I solve this problem in liquid?

Phlow
  • 688
  • 4
  • 14
  • 1
    A [post about even and odd items](http://stackoverflow.com/questions/8980192/liquid-templates-even-odd-items-in-for-loop) may help you. But if not, perhaps "`if forloop.last` close the
    ", before the second cycle, and then `if not forloop.last` around the cycle may also work.
    – Paulo Almeida Dec 12 '13 at 17:45
  • Isn't there a simple way to ask "if items number even do this" and "if items number odd do that"? at the end i could than just ask "is it the last item? if it's odd please add something"... – Phlow Dec 13 '13 at 20:20
  • There is a modulo filter. I don't know if you can `capture` the result of that and use it as a variable. – Paulo Almeida Dec 13 '13 at 21:14
  • I am sure I will solve the problem. Thank you Paulo for helping me out. – Phlow Dec 13 '13 at 21:44

0 Answers0