--- On Wed, 3/2/11, Andy Wardley <[email protected]> wrote:
> From: Andy Wardley <[email protected]> > Subject: Re: [Templates] convert to lower case in an expression? > To: "Sean McAfee" <[email protected]> > Cc: [email protected] > Date: Wednesday, March 2, 2011, 12:41 AM > 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: Would be nice to do it like adding a new filter than subclass.. my $config = { FILTERS => {filter_a => filter_a()}, VMETHODs => { }, }; my $template = Template->new($config); can it be done for vmethod? > > 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 > James _______________________________________________ templates mailing list [email protected] http://mail.template-toolkit.org/mailman/listinfo/templates
