Using Symfony 2, I'm trying to print out a label by using
form_widget(form.client)
The label I'm trying to print is containing actual HTML markup:
$builder->add('client', 'text', array('label' => '<a href="#">Client</a>'));
But Symfony autoescapes the label and prints it out as text and not as HTML. So I've tried to use both
form_widget(form.client) | raw
and
{% autoescape false %} form_widget(form.client) {% endautoescape %}
but none of those two methods helped me, the output is still regarded as text and not HTML. Am I missing some setting or am I using it wrong?
Thanks!
Don't put HTML into your classes! Use Custom Form rendering to customize how your labels are rendered.
I think Twig filters should be inside the parenthesis and not outside - have you tried like this :
form_widget(form.client | raw)
Also, I would recommend adding the tag not in the class but directly in the template :
<a href="{{ your.variable }}"> {{ form_label(form.client) }} </a>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.