I use Twig as a template for my PHP web application.
I would like to know if there is a quick way to get many elements in a foreach block.
This is my data:
users=>[
["name"=>"User1"],
["name"=>"User2"],
["name"=>"User3"],
["name"=>"User4"],
["name"=>"User5"],
["name"=>"User6"]
]
This will be a standard loop (each element):
<ul>
{% for user in users %}
<li>{{ user.name }}</li>
{% endfor %}
</ul>
But this is what I need in the element block n (in this example n = 3 )
<ul>
<li>User1</li>
<li>User2</li>
<li>User3</li>
</ul>
<ul>
<li>User4</li>
<li>User5</li>
<li>User6</li>
</ul>
Is there a quick way to do this in Twig, or do I need to prepare the data differently with another level of submachine?
source
share