Reputation: 796
Is there a way with Symfony 2 forms to add HTML inside a label?
I want:
<label for="myfield"><span class="photo">My label</span></label>
How can I write it? None of these ideas work properly as expected:
<span class="photo">{{ form_label(form.myfield) }}</span>
Or
{{ form_label(form.myfield, '<span class="photo">'~myfield~'</span>') }}
Thanks for your help, A
Upvotes: 6
Views: 9815
Reputation: 1092
I think you could do it like this:
enter code here
{{ form_label(form.myfield,'Name of the label') }}
{{ form_errors(form.myfield)}}
{{ form_widget(form.myfield),{attr:{'class':'photo span'}}) }}
Upvotes: 0
Reputation: 3717
Take a look to Symfony2 Form theming documentation, especially to the "Adding a "Required" Asterisk to Field Labels" section.
I am not sure this is the best way to go, but it should work.
Upvotes: 5