Loop in a branch and break after three iterations

I have the following twig code:

{% for likeditem in user.getItemLikes() %} //iterate over each liked items here {% endfor %} 

however, I wanted to repeat only the first 3 elements of user.getItemLikes()

how to do it?

+4
source share
1 answer

It looks like you can use the slice filter for what you are trying to do:

 {% for likeditem in user.getItemLikes()|slice(0,3) %} //iterate over each liked items here {% endfor %} 
+20
source

Source: https://habr.com/ru/post/1482776/


All Articles