http://www.perlmonks.org?node_id=570059
Description: Template Toolkit does not allow recursively including template files, but you can use a VIEW to recurse over a data structure. VIEWs are still experimental but it works for me.
use Template;
use strict;
use warnings;

my $t = Template->new;
my @nodes = (
{name => "one"},
{name => "two", children => [ {name => "red"},
                              {name => "green"} ] },
{name => "three", children => [
  {name => "blah", children => [
    {name => "yakko" },
    {name => "wacko" },
    {name => "dot" }
   ]
  }
]
} );


$t->process("rec.tt", { nodes => \@nodes } );

And the template:

[% VIEW nested_list %]
  [% BLOCK list %]
    <ul>
      [% FOREACH i IN item %]
        <li>[% i.name %]</li>
        [% IF i.children %]
          [% view.print(i.children.list) %]
        [% END %]
      [% END %]
    </ul>
  [% END %]
[% END %]

[% nested_list.print(nodes) %]

And that outputs: