[Dancer-users] Custom FILTERS for TemplateToolkit in dancer?
Assaf Gordon
gordon at cshl.edu
Thu Oct 13 02:25:52 CEST 2011
Assaf Gordon wrote, On 10/12/11 19:06:
> Has anyone managed to add a custom Template-Toolkit Filter when using Dancer ?
Answering myself...
During initialization (when Dancer just loads, before the template engine is created), add the following code:
=============
sub custom_filter(@) {
my $text = shift ;
$text = reverse $text;
return $text;
}
config->{engines}->{template_toolkit}->{FILTERS} = { 'my_custom_filter' => \&custom_filter } ;
=============
Then, I can use the following template code:
[% VAR | my_custom_filter %]
It works thanks to the foresight of Dancer's developers (Thanks!!!) to pass-through all the config variables to template-toolkit's NEW.
Note that this (Template Toolkit's static filters) can't be specified in the YML config file, because the value is not a string, it must be a code ref, so this needs to be done in your code.
-assaf.
More information about the Dancer-users
mailing list