Click to See Complete Forum and Search --> : HTML::Template TMPL_LOOP within TMPL_LOOP syntax is driving me up the wall!


Ultimater
10-10-2005, 12:25 AM
http://search.cpan.org/~samtregar/HTML-Template-2.7/Template.pm#TMPL_LOOP
cpan gives the following code:

$template->param(LOOP => [
{ name => 'Bobby',
nicknames => [
{ name => 'the big bad wolf' },
{ name => 'He-Man' },
],
},
],
);

Can I get an example program that uses two TMPL_LOOP tags nested within each other?

FYI, My template file looks like so but I can't seem to find the syntax to feed the template the information it needs from my arrays:

<TMPL_LOOP NAME="THEATER_NAME_LOOP">
THEATER <TMPL_VAR NAME="THEATER_COUNT">: <TMPL_VAR NAME="THEATER_NAME"> <br>
<TMPL_LOOP NAME="MOVIE_NAME_LOOP">
+MOVIE <TMPL_VAR NAME="MOVIE_COUNT">: <TMPL_VAR NAME="MOVIE_NAME"><br>
</TMPL_LOOP>
</TMPL_LOOP>

I can careless what is contained in the arrays, I just want to see a working example. Thanks in advance.

Ultimater
10-10-2005, 02:04 AM
Figured it out :)

my $i=1;
my @loop_data = ();

while (@t_names) {
my %row_data;


$row_data{THEATER_NAME} = shift @t_names;
$row_data{THEATER_COUNT} = $i;
$row_data{MOVIE_NAME_LOOP} = [ {MOVIE_COUNT => 1,MOVIE_NAME=> 2},];

push(@loop_data, \%row_data);
$i++;
}

my $template = HTML::Template->new(filename => "".$ENV{'DOCUMENT_ROOT'}."/testing_template.html");
$template->param(THEATER_NAME_LOOP => \@loop_data);

print $template->output;