I think I've found a bug in Template Toolkit 2.14. Please point out
my error
if I've missed something here.
If data passed to process() for interpolation into the template
contains just a
single hashref as an array element, then it interprets the hashref as
an array. In
the example below, the second list (with just one element) is handled
incorrectly.
Cheers,
-Jason
#!/usr/bin/env perl
use strict;
use Template;
my $template = "
Should show 2 entries:
[% FOREACH i = data.mylist1 %]
[% loop.index %]: [% i.a %],[% i.c %]
[% END %]
Should show 1 entry:
[% FOREACH i = data.mylist2 %]
[% loop.index %]: [% i.one %],[% i.two %]
[% END %]
";
my $data = {};
bless $data, "foo";
my $tt = new Template;
$tt->process(\$template, { data => $data });
package foo;
sub mylist1 {
return (
{
a => "b",
c => "d",
},
{
a => "f",
c => "g",
},
);
}
sub mylist2 {
return (
{
one => "111",
two => "222",
},
);
}
_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates