I need to iterate through nested entities in a Twig template.
Entity A -> OneToMany relationship with Entity B
Entity B -> OneToMany relationship with Entity C
Relationships are set up properly (at least from what I can tell) and in the controller I can iterate through the nested ORM results.
However, when I try the following in the Twig template, I receive an error that states that a method (property of Entity B) does not exist.
Here’s the code I use in the Twig template:
{% for entityB in entityA.collection %}
{% for entityC in entityB.collection %}
{{ entityC.property }}
{% endfor %}
{% endfor %}
The error that is thrown states that entityC.property does not exist.
Am I missing something?
Thanks,
JB
The short answer is that you can. It must be an issue with your entities.
Check your spelling of the property on entityC.property and try printing entityC.id or another property that you know exists. The code you have is fine.