twig: take only the first 3 elements of a foreach loop [duplicate]

I have this code in twig:

  {% for row in api_data.response %}
<div class="singlePostContainer">
    <span class="postNumber">
        01
    </span>
    <div class="postTextContainer">
        <div class="postTitle">
            {{row.album}}
        </div>
        <div class="postDate">
            {{row.anno}}
        </div>
        <div class="postAuthor">
            author
        </div>
    </div>
</div>
 {% endfor %}

api_data.response contains 11 arrays of objects (https://prova1api.herokuapp.com/RedHotCHiliPeppersDiscography) but I would like to take only the first 3 results … I know how to do it in a normal php file, but I don’t know how to do it with this twig code syntax using symfony

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

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