Turn off escaping in Symfony 2 / twig

2019-02-22 03:26发布

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': '󰀧'} }) }}

I have found a few topics on this for 1.X versions of Symfony, but nothing for 2.

Thanks!

标签: symfony twig
2条回答
我命由我不由天
3楼-- · 2019-02-22 03:56

Probably what you need is the raw tag or filter. Also take a look at the autoescape tag.

To turn autoescaping off globally, set the autoescape option to false in config.yml:

twig:
    # ...
    autoescape: false
查看更多
登录 后发表回答