Symfony2: custom HTML inside label

Is there a way with Symfony 2 forms to add HTML inside a label?

I want to:

<label for="myfield"><span class="photo">My label</span></label>

How can i write None of these ideas work properly:

<span class="photo">{{ form_label(form.myfield) }}</span>

or

{{ form_label(form.myfield, '<span class="photo">'~myfield~'</span>') }}

Thanks for your help, A

+5
source share
2 answers

Take a look at the Symfony2 Form documentation , especially the “ Add” Required Asterisk to Field Label section .

I'm not sure if this is the best way to go, but it should work.

+5
source

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'}}) }}
0
source

All Articles