Custom FOSUserBundle Login Template using Bootstrap

前端 未结 2 1198
逝去的感伤
逝去的感伤 2021-01-03 06:12

I\'ve installed Symfony2, FOS User Bundle and Twitter Bootstrap.

Then I setup the /app/Resources/FOSUserBundle/views/layout.html.twig template to override FOSUserBun

相关标签:
2条回答
  • 2021-01-03 06:38

    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 have to create app/Resources/FOSUserBundle/views/Security/login.html.twig and ommit the wrapping {% block fos_user_content %} found in FOSUserBundle's login.html.twig in order to have it 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 template.

    0 讨论(0)
  • 2021-01-03 06:55

    Richard Miller's post has 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 couldn't get app.request.partial to work, and decided choosing based on xmlRequest wasn't ideal.

    0 讨论(0)
提交回复
热议问题