Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
海
我知道我可以通过 |e 过滤器传递变量来转义变量。但是如果我将变量与另一个字符串连接起来,一切都会被转义:
{% set escaped = "<div></div>"|e %} {{ '<div>'+escaped+'</div>' }}
结果是:
<div><div></div></div>
我怎样才能只转义变量,所以字符串的其余部分将作为 HTML 插入?
谢谢你的帮助!
我找到了解决方案:
{% set escaped = "<div></div>"|e %} {{ '<div>'|safe + escaped + '</div>'|safe }}