4
votes

I am defining my own twig layout for new user registration and I have everything laid out the way I want it with the exception of the plainPassword field from the FOSUserBundle.

<p class="left">
   {{ form_widget(form.plainPassword) }}
</p>
<div class="clearfix"></div>

The code above displays both the password and verification block. I would like to break this up into the 4 elements of form.plainPassword.label, form.plainPassword.field, form.plainPassword2.label, and form.plainPassword2.field. I cannot figure out what to put in the form_label() and form_widget() calls.

<p class="left">
   {{ form_label( ??? ) }}
   {{ form_widget( ??? ) }}
</p>
<p class="left">
   {{ form_label( ??? ) }}
   {{ form_widget( ??? ) }}
</p>
<div class="clearfix"></div>

I am assuming this can be done.

2

2 Answers

25
votes

I had the same problem. My solution (seems to be official :) :

{{ form_label (form.plainPassword.first) }}   
{{ form_widget (form.plainPassword.first) }}  

{{ form_label (form.plainPassword.second) }}   
{{ form_widget (form.plainPassword.second) }}

Hope it can helps !

2
votes

This blog post shows how to output a repeated field in twig.

http://blogsh.de/2011/10/19/how-to-use-the-repeated-field-type-in-symfony/

But in short this worked for me:

{{ form_label (form.plainPassword.children['New Password']) }}   
{{ form_widget (form.plainPassword.children['New Password']) }}  

{{ form_label (form.plainPassword.children['Confirm Password']) }}   
{{ form_widget (form.plainPassword.children['Confirm Password']) }}                    

I have to say I'm sure using .children isnt the best/official way of doing it, but it works!