I just started using TT and had a question about iterating over an
array. I want to put a fixed number of array items on a HTML row.
Something like the following:
# Have an array of hash:
my @array = map {{id=>"abc$_"}} (1..99);
my $aref = [EMAIL PROTECTED];
my $vars = {
aref => $aref
};
# Want to mimic this in template:
for ([EMAIL PROTECTED]) {
print "<tr>" if $_ == 0;
print "<td>$aref->[$_]{id}</td>";
print "</tr>\n<tr>" unless ($_+1)%4;
print "</tr>" if $_ == [EMAIL PROTECTED];
}
# To get this output:
<tr><td>abc1</td><td>abc2</td><td>abc3</td><td>abc4</td></tr>
<tr><td>abc5</td><td>abc6</td><td>abc7</td><td>abc8</td></tr>
<tr><td>abc9</td><td>abc10</td><td>abc11</td><td>abc12</td></tr>
<tr><td>abc13</td><td>abc14</td><td>abc15</td><td>abc16</td></tr>
I know how to do a simple iteration using [% FOREACH aref %] and I know
about aref.size which would give the equivalent of scalar(@$aref) but
I'm not sure how to accomplish the above. Any help would be great.
Thanks,
John
- [Templates] Using array indexes John Wang
- Re: [Templates] Using array indexes Buddy Burden
- Re: [Templates] Using array indexes John Wang
- [Templates] arghhh, string replacement...hel... JustSome person
- Re: [Templates] arghhh, string replaceme... Josh Rosenbaum
- Re: [Templates] arghhh, string repl... Josh Rosenbaum
- Re: [Templates] arghhh, string repl... JustSome person
- RE: [Templates] arghhh, string ... Sergey Martynoff
- Re: [Templates] arghhh, string ... Josh Rosenbaum
- Re: [Templates] arghhh, str... JustSome person
- Re: [Templates] arghhh, str... Josh Rosenbaum
