开发者

Escaping the content of a template

开发者 https://www.devze.com 2023-04-11 04:28 出处:网络
How can I use the twig i开发者_开发百科nclude function in a template to output the content of another template, escaped for javascript ? Here is what I tried :

How can I use the twig i开发者_开发百科nclude function in a template to output the content of another template, escaped for javascript ? Here is what I tried :

jQuery(".container").append('<div id="my-modal">{% 
  include 'MyBundle:MyFolder:myTemplate.html.twig'
  with {'my_var': var} |escape('js') %}</div>');

But the code inside myTemplate.html.twig is not escaped at all... how can I achieve this?


The Twig team answered me here very fast : https://github.com/fabpot/Twig/issues/459#issuecomment-2286649

Here is what I did:

jQuery(".container").append('<div id="my-modal">{% filter escape('js') %}{% 
  include 'MyBundle:MyFolder:myTemplate.html.twig'
  with {'my_var': var} %}{% endfilter %}</div>');
0

精彩评论

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

关注公众号