0

How can I override the layout of the registration form

Currently the form is

  -username 
  -email  
  -password  
  -verification  

I want the override the layout of this form, lets say, two questions per row

 -username      -email
 additional text   
 -password      -verification

I understand how to write the views (twigs) register.html.twig calls register_content.html.twig which uses;

{{ form_widget(form) }}

how do i override the {{ form_widget(form) }} ?

myTD
  • 1,459
  • 4
  • 17
  • 30

1 Answers1

3

You have to override FosUserBundle registration form template.

You can accomplish an override in the following ways:

  • Define a template with same name into app/resources directory. Together "same name" you have to reproduce the same structure of the bundle. So, if your template is in, i.e., FosUserBundle/views/mainTemplate.html.twig you have to override it by creating a new one template in app/resources/FosUserBundle/views and call it mainTemplate.html.twig

  • You have to create a new bundle from scratch and override getParent() method that have to return a string containing bundle name that you want to override ( FosUserBundle ). Now if you create a new template in the same position of the original, you have overwritten it. This method is not recommended since you have to override controller also.

DonCallisto
  • 29,419
  • 9
  • 72
  • 100
  • Thank you for your response. I have already done what you have recommended. So basically, i copied all those files and override the other templates in that way too. However, for the registration page, I am stuck at this situation. register_content.html.twig (which I have copied and overridden) uses {{ form_widget(form) }}.. How do i override form_widget(form), so that i can actually modify the contents of the form_widget(form)? Thank you so much. – myTD Jan 28 '13 at 08:26
  • @Skyrim1: I suppose that override `form_widget()` isn't a good choice. You have to display all fields manually with `form_widget(fieldName)` where `fieldName` is the field you're interested in – DonCallisto Jan 28 '13 at 08:29
  • Thank you so much for pointing me to the right direction.. I will try to implement manually.. (I was trying to stay away from this, as the form_widget(form) has really cool stuff, that throws error messages, highlights the empty fields, etc... ) Just as an additional question, where does form_widget(form) is stored? So I can look at its contents when manually writing my registration page.. Thank you for your time... – myTD Jan 28 '13 at 08:35
  • I suppose that `form_widget(form)` is a twig extension or a twig function. Look at the twig bundle under vendor folder – DonCallisto Jan 28 '13 at 08:40
  • I think it is coming from here... \Symfony\vendor\symfony\symfony\src\Symfony\Bridge\Twig\Resources\views\Form\form_div_layout.html.twig ... thanks again!!! – myTD Jan 28 '13 at 08:58