-
-
Save superfein/c989162cf606f6318a4eb36ed7a79590 to your computer and use it in GitHub Desktop.
using modulo in liquid to case odd even in a loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% 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