Skip to content

Instantly share code, notes, and snippets.

@joe-dempsey
Created May 10, 2017 14:38
Show Gist options
  • Save joe-dempsey/b9eabf6883647f5b75ad027fc9d461f3 to your computer and use it in GitHub Desktop.
Save joe-dempsey/b9eabf6883647f5b75ad027fc9d461f3 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 %}
@y377
Copy link

y377 commented Feb 18, 2023

Thanks to this modulo usage, originally I can't take integer, with this example, I can take integer, for Jekyll post timeline production

@olivier3lanc
Copy link

Works perfectly, thanks ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment