Very nice. If you don't mind, i'd like to add how to do this with HTML::Mason for posterity, contrast/compare, etc.
Calling component (nodes.html)
<%init> use strict; use warnings; my @nodes = ( {name => "one"}, {name => "two", children => [ {name => "red"}, {name => "green"}, ] }, {name => "three", children => [ {name => "blah", children => [ {name => "yakko" }, {name => "wacko" }, {name => "dot" }, ] }, ] }, ); $m->comp( 'nodes.mas', nodes => \@nodes ); </%init>
and nodes.mas
I added a check to ref() for safety.<%args> @nodes </%args> <ul> % foreach my $i (@nodes) { <li><% $i->{name} %></li> % if (ref( $i->{children} ) eq 'ARRAY') { % $m->comp( 'nodes.mas', nodes => $i->{children} ); % } % } </ul>
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
In reply to Recursively display nested lists with Mason
by jeffa
in thread Recursively display nested lists with Template Toolkit
by friedo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |