我有以下树枝代码:
{% for likeditem in user.getItemLikes() %}
//iterate over each liked items here
{% endfor %}
但是我想只迭代user.getItemLikes()
我该怎么做?
答案 0 :(得分:22)
您似乎可以使用slice过滤器来执行您要执行的操作:
{% for likeditem in user.getItemLikes()|slice(0,3) %}
//iterate over each liked items here
{% endfor %}