On 01/03/2011 22:18, Sean McAfee wrote:
> If you're not aware, it's quite easy to add your own vmethods:
>
>
http://tt2.org/docs/manual/VMethods.html#section_Defining_Custom_Virtual_Methods
I looks like I never got around to documenting the define_vmethod()
method. Mea culpa.
My preferred way is to create my own Template subclass for any
particular project I'm working on. Something like this:
package My::Project::Template;
use base 'Template';
sub new {
my $class = shift;
my $self = $class->SUPER::new(@_);
my $context = $self->context;
$context->stash->set( name => $value );
$context->define_vmethod( item => name => \&f1 );
$context->define_vmethod( list => name => \&f2 );
$context->define_vmethod( hash => name => \&f3 );
$context->define_filter( name => \&f4 );
return $self;
}
Then I use My::Project::Template instead of Template and all the extra
vmethods, etc., are effectively built in.
HTH
A
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates