Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

escape HTML by default in Template Toolkit

Can I somehow configure Template Toolkit so that:

[% foo %]

does what you would now need to say:

[% foo | html %]

that is, escape HTML in foo? And do something else, like:

[% foo | noHtml %]

if I don't want to escape?

like image 394
JoelFan Avatar asked Dec 16 '10 22:12

JoelFan


2 Answers

Came across your question when trying to answer the same question for myself.

http://search.cpan.org/~mithaldu/Template-AutoFilter/ seems to do what we want, but it does require installing another module. I'm going to give it a try anyway.

like image 160
FalseVinylShrub Avatar answered Sep 21 '22 05:09

FalseVinylShrub


I guess you could create your own stash by extending Template::Stash so that it would by default escape variables.

That said I think it is not a good idea. Better to stick with default behaviour and refrain from custom modifications as they are certainly confusing.

like image 34
jira Avatar answered Sep 18 '22 05:09

jira