Twig, loop filter
2 answers
You can use a slice
filter
{% for i in dates|slice(start, length) %}
<li>{{date}}</li>
{% endfor %}
So, the first time you set start = 0
and length = 4
(if you need 5 items, you shouldn't iterate from 0 to 5 since the number is six), the next time you set and (if you need 5 items, you shouldn't iterate over from 0 to 5, since the number is six), the next time from 5 to 9, and so on ...
+2
source to share