Loops with loops using html-template

M

Me

How do I contruct an array of hash references( or arrays) such that
I can have the following loops in html-template:

<MAIN_LOOPP>
DATA1
DATAN
<OTHER-LOOP>
O-DATA1
O-DATAN
</OTHER-LOOP>
</MAIN_LOOP>
 
P

Paul Lalli

Me said:
How do I contruct an array of hash references( or arrays) such that
I can have the following loops in html-template:

<MAIN_LOOPP>
DATA1
DATAN
<OTHER-LOOP>
O-DATA1
O-DATAN
</OTHER-LOOP>
</MAIN_LOOP>

Assuming you're talking about HTML::Template, the above is not a valid
template file. Perhaps you intended something like this?
<TMPL_LOOP name="main_loop">
<TMPL_VAR name="data">
<TMPL_LOOP name="other_loop">
<TMPL_VAR name="o_data">
</TMPL_LOOP>
</TMPL_LOOP>

In that case, you would construct your data structure like so
[untested]:
my @main_loop = (
{
data=>'data_1',
other_loop => [
o_data => 'o_data1_1',
o_data => 'o_data1_2',
# . . .
o_data => 'o_data1_n',
],
},
{
data=>'data_2',
other_loop => [
o_data => 'o_data2_1',
o_data => 'o_data2_2',
# . . .
o_data => 'o_data2_n',
],
},
# . . .
{
data=>'data_n',
other_loop => [
o_data => 'o_datan_1',
o_data => 'o_datan_2',
# . . .
o_data => 'o_datan_n',
],
},
);
$tmpl->param('main_loop' => \@main_loop);


If I have incorrectly interpreted your request, please post a
short-but-complete *actual* template file that you wish to fill, and
your Perl code that attempts to fill it.

Paul Lalli
 
M

Me

Thanks Paul. You were are correct on all accounts. I put in the
template structure in a hurry, and left out the other details
for easy of a reading.
Paul said:
Me said:
How do I contruct an array of hash references( or arrays) such that
I can have the following loops in html-template:

<MAIN_LOOPP>
DATA1
DATAN
<OTHER-LOOP>
O-DATA1
O-DATAN
</OTHER-LOOP>
</MAIN_LOOP>


Assuming you're talking about HTML::Template, the above is not a valid
template file. Perhaps you intended something like this?
<TMPL_LOOP name="main_loop">
<TMPL_VAR name="data">
<TMPL_LOOP name="other_loop">
<TMPL_VAR name="o_data">
</TMPL_LOOP>
</TMPL_LOOP>

In that case, you would construct your data structure like so
[untested]:
my @main_loop = (
{
data=>'data_1',
other_loop => [
o_data => 'o_data1_1',
o_data => 'o_data1_2',
# . . .
o_data => 'o_data1_n',
],
},
{
data=>'data_2',
other_loop => [
o_data => 'o_data2_1',
o_data => 'o_data2_2',
# . . .
o_data => 'o_data2_n',
],
},
# . . .
{
data=>'data_n',
other_loop => [
o_data => 'o_datan_1',
o_data => 'o_datan_2',
# . . .
o_data => 'o_datan_n',
],
},
);
$tmpl->param('main_loop' => \@main_loop);


If I have incorrectly interpreted your request, please post a
short-but-complete *actual* template file that you wish to fill, and
your Perl code that attempts to fill it.

Paul Lalli
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,177
Messages
2,570,952
Members
47,506
Latest member
tomiy16522

Latest Threads

Top