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">
    <div class="postTextContainer">
        <div class="postTitle">
        <div class="postDate">
        <div class="postAuthor">
 {% endfor %}

api_data.response contains 11 arrays of objects ( 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 *