Skip to content

Instantly share code, notes, and snippets.

@ecmelkytz
Created May 16, 2017 11:28
Show Gist options
  • Save ecmelkytz/836477a90ebe059f66900a9b4df6503e to your computer and use it in GitHub Desktop.
Save ecmelkytz/836477a90ebe059f66900a9b4df6503e to your computer and use it in GitHub Desktop.
<!-- Wraps every three items in div.row -->
<!-- Closes div.row even there is not enough items -->
{% for item in site.data.your_data %}
{% capture modulo %}{{ forloop.index | modulo: 3 }}{% endcapture %}
{% if modulo == '1' %}
<div class="row">
{% endif %}
<div class="col-sm-4 topic">
{{ item.name }}
</div>
{% if modulo == '0' or forloop.last %}
</div>
{% endif %}
{% endfor %}
<!-- Output: -->
<div class="row">
<div class="col-sm-4 topic">
item1
</div>
<div class="col-sm-4 topic">
item2
</div>
<div class="col-sm-4 topic">
item3
</div>
</div>
<div class="row">
<div class="col-sm-4 topic">
item4
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment