Skip to content
Advertisement

Issue with Category tree in symfony

I created a Category Tree in symfony 5

I’ve following:

Category.php Entity:

JavaScript

CategoryReponsitory.php

JavaScript

Controller.php

JavaScript

And the twig template file index.html.twig

JavaScript

It render is correctly, But if the children don’t have any children, it still renders html like image bellow:

enter image description here

I don’t want it, for some reason. How can I fix that. Thank you.

Advertisement

Answer

The behavior for collections seems to be different than for arrays. Since children is an ArrayCollection it’ll always be set. You should check if it contains elements.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement