Symfony2 Twig unlimited child depth

后端 未结 2 768
刺人心
刺人心 2021-01-01 04:49

I have a self-joining table where each folder has a parent, and the depth of this is unlimited. One folder can have another folder as a parent, no restriction on the depth.<

2条回答
  •  天命终不由人
    2021-01-01 05:02

    You need a separate file rendering options that recursively includes itself:

    
    

    options.html.twig:

    {% for folder in folders %}
        
    
        {% include 'options.html.twig' with {'folders': folder.children, 'level': level + 1} %}
    {% endfor %}
    

    I wrote this code right here, so don't expect it to be correct, but it should be enough to give you the idea.

提交回复
热议问题