I have problem with comments display in twig. They are visible if I list them all but I need them to be nested.
This is entity, I thought it should be referenced like this:
/**
* @var \AppBundle\Entity\Comment
*
* @ORM\ManyToOne(targetEntity="AppBundle\Entity\Comment")
* @ORM\JoinColumn(name="parentId", referencedColumnName="id")
*/
private $parentId;
Controller is simple, fetch all comments from db and returns array( with, and without parentId) Following some instruction i added this to main twig file:
<!-- Comments and omments with parentId -->
{% include 'front/main/comments-main.html.twig' with {'commments':comments} %}
Listing all comments works. But in included twig it seems this peace of code
{% if comment.parentId != null %}
{% set children = [] %}
{% set children = children|merge([ comment ]) %}
{% include 'front/main/comments-main.html.twig' with {'comments':children} %}
{% endif %}
does not work. If I echo something it is displayed in the right place, under comment with that id. But with that lines inside if not. Page load very slow and never ends. Like infinite loop. What I am doing wrong?