Search code examples
perlcatalysttemplate-toolkit

How do I use a HTML filter in macro arguments in Template Toolkit?


I have something like this: [% query | html %]

Now I would like to use it as

[% MACRO l(text, args) BLOCK; c.localize(text, args); END; %] 
[% l('text:<b>[_1]</b> no:[_2]', [query | html,2]) %]

If you try that example it will not work because | cannot be used there. That is not accepted by Template Toolkit. I want to HTML-escape query. How can I do that?

To move <b> out of the quotes is not a solution because the translation may not have the same order as above.


Solution

  • You can [% USE HTML %] and escape a specific parameter, for example:

    [% USE HTML %]
    [%# your code above %]
    [% l('text:<b>[_1]</b> no:[_2]',  HTML.escape(query), 2) %]