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.<
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.