|raw

October的输出变量会自动转义,|raw过滤器会将值标记为“安全”,如果raw是最后应用的过滤器,则不会转义。

  1. {# 此变量不会被转义 #}
  2. {{ variable|raw }}

在表达式中使用raw过滤器时要小心:

  1. {% set hello = '<strong>Hello</strong>' %}
  2. {% set hola = '<strong>Hola</strong>' %}
  3. {{ false ? '<strong>Hola</strong>' : hello|raw }}
  4. {# 以上内容不会与之相同 #}
  5. {{ false ? hola : hello|raw }}
  6. {# 但渲染相同 #}
  7. {{ (false ? hola : hello)|raw }}