title: Symfony2 Twig unlimited child depth
body: <p>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.</p>
  
  <p>Today my code looks like this, and I am looking for a way of digging down as deep as it needs without hard-coding each step down, is there perhaps a way to define a twig function with a loop, that calls itself on each round in the loop? </p>
  
  <pre><code>&lt;select id='parent' name='container'&gt;
      &lt;option value='none'&gt;No parent&lt;/option&gt;
          {% for folder in folders %}
              &lt;option value='{{ folder.id }}'&gt;{{ folder.name }}&lt;/option&gt;
                  {% for folder in folder.children %}
                      &lt;option value='{{ folder.id }}'&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;{{ folder.name }}&lt;/option&gt;    
                  {% endfor %}
          {% endfor %}
  &lt;/select&gt;  
  </code></pre>