title: What is the best way to handle recursion in smarty?
body: <p>I found a couple of ways to handle recursion in Smarty, mostly based on including templates into themselves, which seems like ridiculous waste of resources. I found one solution, by Messju over at Smarty that seemed to be just right - but it is not supported and fails in the latest version of smarty :(</p>
  
  <p>For people asking: What I want smarty to print out is a discussion thread that is defined by an array of entries. If an entry has one or more answers, those are listed as children to said entry in an array, and so on.</p>
  
  <pre><code>array(
      array(
          'id'=&gt;0,
          'headline'=&gt;"My parent headline",
          'body'    =&gt;"My parent body",
          'children'=&gt;array(
              array(
                  'id'=&gt;1,
                  'headline'=&gt;"My firstChild headline",
                  'body'    =&gt;"My firstChild body",
                  'children'=&gt;array()
              ),
              array(
                  'id'=&gt;2,
                  'headline'=&gt;"My secondChild headline",
                  'body'    =&gt;"My secondChild body",
                  'children'=&gt;array()
              )
          )
      ),
  );
  </code></pre>
  
  <p>The nested array has an arbitrary depth, and each entry will have an arbitrary number of children. To me this is something I want to do with within the scope of the template, as I consider it pure display logic. I do not want to have to handle HTML or some type of HTML placeholders outside of the template.</p>
  
  <p>I want smarty to print this as nested lists:</p>
  
  <pre><code>&lt;ul&gt;
      &lt;li&gt;
          &lt;h1&gt;My parent headline&lt;/h1&gt;
          &lt;p&gt;My parent body&lt;/p&gt;
          &lt;ul&gt;
              &lt;li&gt;
                  &lt;h1&gt;My firstChild headline&lt;/h1&gt;
                  &lt;p&gt;My firstChild body&lt;/p&gt;
              &lt;/li&gt;
              &lt;li&gt;
                  &lt;h1&gt;My secondChild headline&lt;/h1&gt;
                  &lt;p&gt;My secondChild body&lt;/p&gt;
              &lt;/li&gt;
          &lt;/ul&gt;
      &lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>I'm starting to realize this might be a very case-by-case problem, so I figure I'll just write a smarty plugin to handle this specifically, although I'd rather have an all-around solution.</p>
  
  <p>Is there a way?</p>