[Templates] A bug and a suggestion
Sean McAfee
eefacm at gmail.com
Thu Jan 24 17:37:07 GMT 2008
On Jan 23, 2008 10:12 PM, Kelly Thompson <kalexthompson at gmail.com> wrote:
> I concur.
>
>
> Other than that, I lOVE TT. Really.
> One more thing, you mentioned in the badger book, about creating your own
> virtual methods, but you didn't show how to "use" them.
>
> For instance, I wanted to add substr to a formating issue I had.
>
> use Template::Stash;
>
> $Template::Stash::LIST_OPS->{getit} = sub {
> my $thing = shift;
> $thing = substr($thing, 0, 1);
>
> return $thing;
> }
>
This is a vmethod for scalars, so you need to add it to SCALAR_OPS, not
LIST_OPS. For example:
use Template;
$Template::Stash::SCALAR_OPS->{getit} = sub {
return substr($_[0], 0, 1);
};
Template->new->process(\'<[% x.getit %]>', { x => 'foobar' });
This prints "f".
--Sean
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.template-toolkit.org/pipermail/templates/attachments/20080124/0206759d/attachment.htm
More information about the templates
mailing list