On Jan 23, 2008 10:12 PM, Kelly Thompson <[EMAIL PROTECTED]> 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
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to