Limits for the loop in twig

If you need to make limits in the loop in twig tample, you make use  |slice().

For example, you need show only first three element in loop

{% for child in category.children|slice(0, 3) %}
   <li>
       <a href="{{ child['href'] }}">{{ child['name'] }}</a>
   </li>  
{% endfor %}


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *