On Wednesday, December 17, 2003 at 18:30, Andy Williams wrote:
> In my HTML file I have the following:
> [% FOREACH br = prod.getCategory(category => "XYZ") %]
> # do something with br
> [% END %]
> Then in my code I have this:
> my $prod = new Prod();
> $vars->{product} = {
> getCategory => $prod->getCategory()
> };
Be careful! The last statement calls the method getCategory() on the
$prod object and assigns its _return value_, not a reference to the
method itself, to the hash entry $vars->{product}->{getCategory}.
If you want to call any method of an object you simply have to pass
the object itself along when processing your template, for example:
my $vars = {
'prod' => Prod->new(),
};
# ...
$template->process('test.tt2', $vars);
Then, you can invoke all of its methods in the template.
Best regards,
Axel
_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.template-toolkit.org/mailman/listinfo/templates