Yet another way to do it - but you would have to enable EVAL_PERL which has
plenty of drawbacks (if you used Template::Alloy you could limit the scope of
EVAL_PERL to a smaller area).
In your template put something like the following:
[% PERL %]
require Scalar::Util;
my $copy = $context;
my $real = $stash->get('real_vfield_sub');
my $proxy = sub { $real->($copy, @_) };
$stash->set('vfield', $proxy);
Scalar::Util::weaken($copy);
[% END %]
[% vfield('test') %]
You would then load the template like so:
my $tt = Template->new(
EVAL_PERL => 1,
VARIABLES => {
real_vfield_sub => sub {
my ($context, $txt) = @_;
return "(($context: $txt))\n";
},
},
);
$tt->process('my_template.html');
There are many variations - but this allows you to do more from within your
template. Ultimately the USE plugin option is the better option to go with.
Paul
_______________________________________________
templates mailing list
[email protected]
http://lists.template-toolkit.org/mailman/listinfo/templates