我使用e
标记中的转义Twig过滤器<meta>
转义字符,以防它们包含会破坏标记的引号。问题在于它正在逃避&
字符。我想知道是否有办法不逃避和签署?
<meta property="description" content="{{ description | e }}" />
答案 0 :(得分:3)
你总是可以使用replace作为黑客修复;)
description|e|replace({'\&':'&'})
答案 1 :(得分:3)
不确定这是否适合您的情况,但一般来说,应该通过明确指定上下文来完成html属性的转义:...|e('html_attr')
,cf。 the escape filter docs
答案 2 :(得分:3)
您应该使用html_attr
转义模式,因为您要将结果插入content
属性。
<meta property="description"
content="{{ description | e('html_attr') }}" />
顺便说一句:如果这是HTML而不是XML,那么您的meta
代码应该具有name
属性,而不是property
属性。