Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Recursively display nested lists with Mason

by jeffa (Bishop)
on Aug 29, 2006 at 15:42 UTC ( #570194=note: print w/replies, xml ) Need Help??


in reply to Recursively display nested lists with Template Toolkit

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

<%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>
I added a check to ref() for safety.

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)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://570194]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2022-10-03 21:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred way to holiday/vacation is:











    Results (15 votes). Check out past polls.

    Notices?