Philippe Philippe - 7 months ago 97
Twig Question

Twig nested loop display only the last array

I'm trying to display all events belonging to each organizer. If there is duplicate content for the oragnizer's name, it will only display the events belonging to the organizer with the highest id.

Organizer table

|id |name |
--------------------
|1 |organizer 1 |
|2 |organizer 1 |


Event table

|id |name |organizer_id |
-------------------------------
|1 |event 1 |1 |
|2 |event 2 |2 |


Twig

{% for organizer in organizers %}
{% for event in organizer %}
{{ event.name }}
{% endfor %}
{% endfor %}


Result

event2


Result wished

event1
event2

Answer Source

I’ve solved the problem by adding a constraint of unicity on organiser name. So the Organizer table, can’t have the same organizer name twice

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download