开发者

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

开发者 https://www.devze.com 2023-02-07 21:03 出处:网络
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; %]

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.


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) %]
0

精彩评论

暂无评论...
验证码 换一张
取 消