问题描述
我正在使用 Symfony 中的表单构建器创建一个表单.我在我的复选框的树枝文件中添加了一个属性,其中包含一个与号和英镑符号,Symfony 会自动转义与号,这会阻止它正确显示.无论如何要在树枝文件或控制器中逐个关闭转义,或者在配置中将其完全关闭?
I'm creating a form using the form builder in Symfony. I am adding an attribute into the twig file for my checkboxes which contains an ampersand and pound sign, Symfony is automatically escaping the ampersand which stops it displaying correctly. Is there anyway to turn off escaping on a per case basis in either the twig file or the controller, or switch it off completely in the config?
{{ form_widget(form.checkbox, { 'attr': {'data-icon-checkmark': '󰀦', 'data-icon-checkmark-checked': '󰀧'} }) }}
我在 Symfony 的 1.X 版本中找到了一些关于此的主题,但在 2 中没有找到.
I have found a few topics on this for 1.X versions of Symfony, but nothing for 2.
谢谢!
推荐答案
可能你需要的是 raw
标签 或 filter.另请查看 autoescape
标签.
Probably what you need is the raw
tag or filter. Also take a look at the autoescape
tag.
要全局关闭自动转义,请在 config.yml
中将 autoescape
选项设置为 false
:
To turn autoescaping off globally, set the autoescape
option to false
in config.yml
:
twig:
# ...
autoescape: false
这篇关于在 Symfony 2/twig 中关闭转义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!