Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save superfein/c989162cf606f6318a4eb36ed7a79590 to your computer and use it in GitHub Desktop.
Save superfein/c989162cf606f6318a4eb36ed7a79590 to your computer and use it in GitHub Desktop.
using modulo in liquid to case odd even in a loop
{% comment %}
Here we loop through a blog and use modulo to case odd/even.
Dead simple.
{% endcomment %}
{% for article in blog.articles %}
{% assign mod = forloop.index | modulo: 2 %}
{% if mod == 0 %}
<!-- it's even so do something...-->
{% else %}
<!-- it's odd so do something else... -->
{% endif %}
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment