Skip to content

Instantly share code, notes, and snippets.

@DanRader
Last active February 25, 2017 22:32
Show Gist options
  • Select an option

  • Save DanRader/5854822cbb4bd756f642e9024190a088 to your computer and use it in GitHub Desktop.

Select an option

Save DanRader/5854822cbb4bd756f642e9024190a088 to your computer and use it in GitHub Desktop.
Alternating Rows using forloop.index and modulo
{% for posts in site.posts %}
{% assign loopindex = forloop.index | modulo: 6 %}
{% if loopindex == 1 %}
<div> {{ forloop.index }}
{% elsif loopindex == 2 %}
{{ forloop.index }}
{% elsif loopindex == 3 %}
{{ forloop.index }} </div>
{% elsif loopindex == 4 %}
<div class="foo"> {{ forloop.index }}
{% elsif loopindex == 5 %}
{{ forloop.index }}
{% elsif loopindex == 0 %}
{{ forloop.index }} </div>
{% endif %}
{% if forloop.last == true %}
</div>
{% endif %}
{% endfor %}
<div class="container blog-list-wrapper">
{% for post in site.posts %}
{% assign loopindex = forloop.index | modulo: 6 %}
{% if loopindex == 1 %}
<div class="row blog-list"> {% include blog/list-item.html %}
{% elsif loopindex == 2 %}
{% include blog/list-item.html %}
{% elsif loopindex == 3 %}
{% include blog/list-item.html %} </div>
{% elsif loopindex == 4 %}
<div class="row blog-list push"> {% include blog/list-item.html %}
{% elsif loopindex == 5 %}
{% include blog/list-item.html %}
{% elsif loopindex == 0 %}
{% include blog/list-item.html %} </div>
{% endif %}
{% if forloop.last == true %}
</div>
{% endif %}
{% endfor %}
</div>
@DanRader
Copy link
Author

DanRader commented Feb 25, 2017

Playing with numbers only —output of alternatingrows.html
screenshot 2017-02-25 17 31 30

high-fi Results
screenshot 2017-02-25 17 28 20

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