Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save keyurshah/651f6f411c43faf2d99843e3d7d701db to your computer and use it in GitHub Desktop.
Save keyurshah/651f6f411c43faf2d99843e3d7d701db to your computer and use it in GitHub Desktop.
[Collection loop] Check odd/even
{% for product in collection.products %}
{% comment %}
{% capture remainder %}{{forloop.index | modulo: 2}}{% endcapture %}
{% if remainder == '0' %}
{% assign is_even = true %}
{% else %}
{% assign is_even = false %}
{% endif %}
{% if is_even == false %}<ul class="product-grid clearfix">{% endif %}
<li{% cycle '', ' class="last-in-row"' %}>
{% include 'product-grid-item' %}
</li>
{% if is_even %}</ul>{% endif %}
{% endcomment %}
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment