-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsplit-items-between-columns.html
47 lines (43 loc) · 1.58 KB
/
split-items-between-columns.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<!-- Split FAQ entries between two columns -->
<div class="row">
<div class="col-md-6">
<ul>
{% for post in site.categories.frequently-asked-questions %}
{% assign half = forloop.length | divided_by: 2 %}
{% if forloop.index <= half %}
<li><a href="{{ post.url }}">{{ post.title }}</a></li>
{% endif %}
{% endfor %}
</ul>
</div>
<div class="col-md-6">
<ul>
{% for post in site.categories.frequently-asked-questions %}
{% assign half = forloop.length | divided_by: 2 %}
{% assign modulo = forloop.length | modulo: 2 %}
{% assign remainder = half | plus: modulo %}
{% if forloop.rindex <= remainder %}
<li><a href="{{ post.url }}">{{ post.title }}</a></li>
{% endif %}
{% endfor %}
</ul>
</div>
</div>
<!-- Split FAQ entries between three columns -->
<div class="row">
{% for post in site.categories.frequently-asked-questions %}
{% assign first_third = forloop.length | divided_by: 3 %}
{% assign next_third_start = forloop.length | divided_by: 3 | plus: 1 %}
{% assign next_third_end = forloop.length | divided_by: 3 | times: 2 %}
{% assign last_third_start = forloop.length | divided_by: 3 | times: 2 | plus: 1%}
{% if forloop.first or forloop.index == next_third_start or forloop.index == last_third_start %}
<div class="col-md-4">
<ul>
{% endif %}
<li><a href="{{ post.url }}">{{ post.title }}</a></li>
{% if forloop.index == first_third or forloop.index == next_third_end or forloop.last %}
</ul>
</div>
{% endif %}
{% endfor %}
</div>