Escaping the content of a template
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>');
精彩评论