Re: [Dancer-users] Custom FILTERS for TemplateToolkit in dancer?
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-meth... Cheers Matt ----- "Assaf Gordon" <gordon@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@perldancer.org http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
Hello Matthew, Matthew Vickers wrote, On 10/12/11 19:32:
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; };
Thanks for the suggestion, but while it does add a sub to the template toolkit's namespace, it doesn't add it as a filter. I'm looking for a way to use filters as described here: http://search.cpan.org/~abw/Template-Toolkit-2.22/lib/Template/Manual/Direct... To be able to run template code as: [% VAR | my_custom_filter %] OR [% FILTER my_custom_filter %] lots of text [% END %] It seems this requires adding the filters in the template object creation step. Didn't yet find a way to do it.
participants (2)
-
Assaf Gordon -
Matthew Vickers