Hi Doug,
You have a few syntax errors below. Your code should read:
$html= Template->new() || die $Template::ERROR;
#
# Here is a hash reference of values
#
my $hash_ref = { 'key' => "one",
'value' => "two",
};
#
# Here we have an array of hash reference values. This example has
really been dumbed down to make it simple
#
for (my $i=0; $i <=6; $i++) {
push (@list,%hash);
}
my $vars = { List => \...@list, };
$html->process("test.tmpl",$vars) || die $html->error;
The key changes were using hash references instead of hashes. When
using the hash as you did,
the hash will expand into a list and not become an atomic item in the
array like you expected.
For more information about hash references I recommend the perlref and
perllol documentation:
http://perldoc.perl.org/perlref.html
http://perldoc.perl.org/perllol.html
> -------------------------------------------------------------------------------------------------
> Here is the Template file
> -------------------------------------------------------------------------------------------------
> Size of list is [% List.size %]
> [% FOREACH item IN List -%]
> [%# How do we reference one entry in the array? %]
> key is [% item.key -%]<br>
> value is [% item.value -%]<br>
> [% END -%]
>
> Also List.size returns 14 as the size and not 7 like I'd expect
This is because of the hash dumping it's keys and values into the
array, and is why you need a hash reference instead.
Clayton
--
Clayton Scott
[email protected]
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates