This post originated from an RSS feed registered with Java Buzz
by Chris Winters.
Original Post: Simple arrays in HTML::Template
Feed Title: cwinters.com
Feed URL: http://www.cwinters.com/search/registrar.php?domain=jroller.com®istrar=sedopark
Feed Description: Chris Winters on Java, programming and technology, usually in that order.
Are you an HTML::Template user? Can you tell me how to display simple scalars (versus hashrefs) in an array? To put it more concretely, I have something like the following in Template Toolkit:
my @names = qw( John Paul Ringo );
my $template = Template->new();
$template->process( \*DATA, { names => \@names } );
__DATA__
You listed the following names:
[% FOREACH name = names %]
* [% name %]
[% END %]
Is there an equivalent in HTML::Template? Because from looking over the docs it appears I need to move the data into hashrefs within the array, which is really annoying if you're trying to build a framework that works on multiple templating systems:
my @names = ( { name => 'John' },
{ name => 'Paul' },
{ name => 'Ringo' } );
my $template = HTML::Template->new( filehandle => *DATA );
$template->param( names => \@names );
print $template->output();
__DATA__
You listed the following names:
<TMPL_LOOP NAME="names">
* <TMPL_VAR NAME="name">
</TMPL_LOOP>