#! /usr/bin/perl
use warnings; use strict;
use HTML::Template;
use Data::Dumper;
my $text = "bar=\n";
my $template = HTML::Template->new(scalarref => \$text,
loop_context_vars => 1);
my @a = ({bar => 10}, {bar => 20});
$template->param(foo => \@a);
my @array = $template->param('foo');
print Dumper(@array);
$template->param(foo => \@array);
$template->output;
####
$VAR1 = [
{
'bar' => 10
},
{
'bar' => 20
}
];
HTML::Template->output() : fatal error in loop output : Not a HASH reference at /usr/share/perl5/HTML/Template.pm line 3059.
##
##
#! /usr/bin/perl
use warnings; use strict;
use HTML::Template;
use Data::Dumper;
my $text = "bar=\n";
my $template = HTML::Template->new(scalarref => \$text,
loop_context_vars => 1);
$template->param(foo => [{bar => 10}, {bar => 20}]);
my $array_ref = $template->param('foo');
if ($array_ref) {
print Dumper($array_ref);
print Dumper($array_ref->[1]);
#
# add a new element
#
push (@$array_ref, {bar => 30});
$template->param(foo => $array_ref);
}
print $template->output;