Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

looping in twig and break after three iteration

Tags:

twig

I have the following twig code:

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

however I wanted to iterate only the first 3 items of user.getItemLikes()

how do I do so?

like image 806
aherlambang Avatar asked May 26 '13 01:05

aherlambang


1 Answers

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 %}
like image 140
go-oleg Avatar answered Oct 17 '22 13:10

go-oleg