Custom FOSUserBundle Login Template Using Bootstrap

I installed Symfony2, FOS User Bundle and Twitter Bootstrap.

Then I customize the /app/Resources/FOSUserBundle/views/layout.html.twig template to override FOSUserBundle to use my site template.

Everything works if I have a link to / login on the main page.

Now I want to implement a template similar to a template, where the login form is part of the main template.

The closest I have is to use it in the main template:

{% render controller("FOSUserBundle:Security:login") %} 

I can override the html layout so as not to redistribute the main template, but this removes all styles from / login

Any ideas on how I can handle both scenarios?

+4
source share
2 answers

Richard Miller's post helped me achieve what I was trying to do.

http://richardmiller.co.uk/2013/02/18/symfony2-ajax-and-full-page-templates/

 {% extends app.request.attributes.get('partial') ? '::ajax-layout.html.twig' : '::full-layout.html.twig' %} 

I could not get app.request.partial to work, and decided that the choice based on xmlRequest was not ideal.

0
source

You were almost there :)

you can include the login form in any other template using the render function.

 {% render controller("FOSUserBundle:Security:login") %} 

... you just need to create an application / resources / FOSUserBundle / views / Security / login.html.twig and omit the wrapper {% block fos_user_content %} found in FOSUserBundle login.html.twig to return the form directly:

 {% if error %} <div>{{ error|trans }}</div> {% endif %} <form action="{{ path("fos_user_security_check") }}" method="post"> <input type="hidden" name="_csrf_token" value="{{ csrf_token }}" /> <label for="username">{{ 'security.login.username'|trans }}</label> <input type="text" id="username" name="_username" value="{{ last_username }}" required="required" /> <label for="password">{{ 'security.login.password'|trans }}</label> <input type="password" id="password" name="_password" required="required" /> <input type="checkbox" id="remember_me" name="_remember_me" value="on" /> <label for="remember_me">{{ 'security.login.remember_me'|trans }}</label> <input type="submit" id="_submit" name="_submit" value="{{ 'security.login.submit'|trans }}" /> </form> 

Then adjust it to fit your pattern.

+12
source

Source: https://habr.com/ru/post/1486430/


All Articles