Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks

currently i have this data structure

$nodes = [ { 'name' => 'Testing Message', 'children' => [ { 'name' => 'Hello world', 'children' => [ { 'name' => 'inside', 'children' => [], 'id' => '3' } ], 'id' => '2' } ], 'id' => '1' } ];

and i am using this block in Template Toolkit to get the output :

[% VIEW nested %] [% BLOCK list %] <ul> [% FOREACH i IN item %] <li>[% i.name %]</li> [% IF i.children.size %] [% view.print(i.children.list) %] [% END %] [% END %] </ul> [% END %] [% END %] [% nested.print(nodes) %]
this will generate the output like this:
<ul> <li>Test</li> <ul> <li>Hello</li> <ul><li>inside</li> </ul> </ul> </ul>

Expected output:

<ul> <li>Test <ul> <li>Hello <ul><li>inside</li> </ul> </li> </ul> </li> </ul>

Replies are listed 'Best First'.
Re: Valid Nested Output
by Corion (Patriarch) on May 17, 2010 at 14:18 UTC

    If you want to output the closing </li> after having output the body of the element, don't output it above the body of the element.

    [% FOREACH i IN item %] <li>[% i.name %]<!-- </li> --> [% IF i.children.size %] [% view.print(i.children.list) %] [% END %] </li> [% END %]
      I wonder how I missed this ... thanks for your help