[Dancer-users] Custom FILTERS for TemplateToolkit in dancer?

Matthew Vickers mvickers at quispiam.com
Thu Oct 13 01:32:56 CEST 2011



Hi Assaf,

I could be completely off base, and please tell me if I am, when I need to use custom code in the template I use 

before_template sub {
    my $tokens = shift;
    $tokens->{'my_custom_filter'} = &custom_filter;
};

Then I call the custom helper in the template like so

<h1><% custom_filter("Hello World") %></h1>

I have written a basic post here: 

http://www.quispiam.com/blog/post.php?s=2011-09-21-adding-custom-helper-methods-to-dancer-templates

Cheers

Matt


----- "Assaf Gordon" <gordon at cshl.edu> wrote:

> Hello,
> 
> Has anyone managed to add a custom Template-Toolkit Filter when using
> Dancer ?
> 
> Using TT directly, the code would looks like this:
> ======
> sub my_custom_filter {
> 	my $text = shift ;
> 	## Do something  to $text;
> 	return $text;
> }
> 
> my $tt = Template->new( {
> 	FILTERES => { 'my_custom_filter' => \&my_custom_filter }
>         });
> ======
> 
> 
> Using Dancer, I see the TT->New() call is in
> "Dancer/Template/TemplateToolkit.pm",
> and I could even possibly add configuration options using
> "config.yml", but how do I specify a reference to a sub in my code ?
> 
> Any suggestions will be appropriated,
> 
> Thanks,
>  -assaf.
> 
> _______________________________________________
> Dancer-users mailing list
> Dancer-users at perldancer.org
> http://www.backup-manager.org/cgi-bin/listinfo/dancer-users


More information about the Dancer-users mailing list