How to make 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) %}
       <a href="{{ child['href'] }}">{{ child['name'] }}</a>
{% endfor %}

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
The comment language code.