Hi mhearse,

In your script you have table_data_begin_row and in your template you have table_data_begin_loop which may be part of the problem.

That particular var is hard coded into your script so you could put it in the template (also table_data_close_row).

I can't run your script to know if that is only snag but here's a snippet showing how I might do it. Notice the use of Data::Dumper which is excellent for these type of problems.

#!/bin/perl5 use strict; use warnings; use Data::Dumper; use HTML::Template; $Data::Dumper::Indent = 1; $Data::Dumper::Sortkeys = 1; my $data = [ [qw{one two three}], [qw{four five six}], [qw{seven eight nine}], ]; my @outer_loop; for my $outer (@{$data}){ my @inner_loop; for my $inner (@{$outer}){ push @inner_loop, {data => $inner}; } push @outer_loop, {inner_loop => \@inner_loop}; } print Dumper \@outer_loop; my $param = {outer_loop => \@outer_loop}; my $tmpl = do{local $/;<DATA>}; my $t = HTML::Template->new(scalarref => \$tmpl) or die qq{tmpl obj fa +iled\n}; $t->param($param); print $t->output; __DATA__ <TMPL_LOOP NAME=outer_loop> --------------------------- <TMPL_LOOP NAME=inner_loop> <TMPL_VAR NAME=data> </TMPL_LOOP> </TMPL_LOOP>
output (Dumper output followed by H::T output):
$VAR1 = [ { 'inner_loop' => [ { 'data' => 'one' }, { 'data' => 'two' }, { 'data' => 'three' } ] }, { 'inner_loop' => [ { 'data' => 'four' }, { 'data' => 'five' }, { 'data' => 'six' } ] }, { 'inner_loop' => [ { 'data' => 'seven' }, { 'data' => 'eight' }, { 'data' => 'nine' } ] } ]; --------------------------- one two three --------------------------- four five six --------------------------- seven eight nine

In reply to Re: Help with nested loop in HTML::Template by wfsp
in thread Help with nested loop in HTML::Template by mhearse

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.