Quoting Rolf Herzog <[EMAIL PROTECTED]> [14 Feb-02 06:49]:
> what I am dong wrong in this template snippet?
>
> [% FOREACH row = data_rows %]
> <tr>
> [% FOREACH col = head_cols %]
> <td align="left" bgcolor="#ffffff">
> <font face=arial size=2>"[% row.${col.name} %]</font>
> </td>
> [% END %]
> </tr>
> [% END %]
>
> The "row" variable in the inner loop doesn't change. So I have
> the correct number of lines, but it is always the same line.
I used this code:
use Template;
my $data = {
head_cols => [
{ name => 'one' },
{ name => 'two' },
{ name => 'three' },
],
data_rows => [
{ one => 1, two => 2, three => 3, },
{ one => 4, two => 5, three => 6 },
{ one => 7, two => 8, three => 9 },
]
};
my $t = Template->new;
$t->process(\*DATA, $data);
__DATA__
[% FOREACH row = data_rows %]
<tr>
[% FOREACH col = head_cols %]
<td align="left" bgcolor="#ffffff">
<font face=arial size=2>"[% row.${col.name} %]</font>
</td>
[% END %]
</tr>
[% END %]
To achieve these results:
<tr>
<td align="left" bgcolor="#ffffff">
<font face=arial size=2>"1</font>
</td>
<td align="left" bgcolor="#ffffff">
<font face=arial size=2>"2</font>
</td>
<td align="left" bgcolor="#ffffff">
<font face=arial size=2>"3</font>
</td>
</tr>
<tr>
<td align="left" bgcolor="#ffffff">
<font face=arial size=2>"4</font>
</td>
<td align="left" bgcolor="#ffffff">
<font face=arial size=2>"5</font>
</td>
<td align="left" bgcolor="#ffffff">
<font face=arial size=2>"6</font>
</td>
</tr>
<tr>
<td align="left" bgcolor="#ffffff">
<font face=arial size=2>"7</font>
</td>
<td align="left" bgcolor="#ffffff">
<font face=arial size=2>"8</font>
</td>
<td align="left" bgcolor="#ffffff">
<font face=arial size=2>"9</font>
</td>
</tr>
This looks OK to me. What versions of stuff are you using?
(darren)
--
You can never entirely stop being what you once were. That's why
it's important to be the right person today, and not put it off
till tomorrow.
-- Larry Wall