Overriding FOSUserBundle Login Form

jriggs picture jriggs · Nov 5, 2013 · Viewed 19.7k times · Source

Im following the documentation here:https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/overriding_templates.rst

I chose to Create A Child Bundle And Override Template so in my bundle I have

class MyBundle extends Bundle
{
    //declare bundle as a child of the FOSUserBundle so we can override the parent bundle's templates
    public function getParent()
    {
        return 'FOSUserBundle';
    }

}

In my bundle I have added the following files

MyBundle
      \Resources
               \views
                     \Security
                      login.html.twig

Matching the FOS bundle structure as mentioned in the documentation

login.html.twig

{% extends 'AnotherBundle::layout.html.twig' %}

{% block title %}Log In{% endblock %}

{% block content %}
    {% block fos_user_content %}{% endblock %}
{% endblock %}

When I go to the login page my header loads fine but there's no login form, what am doing wrong?

Answer

yanyabo111 picture yanyabo111 · Nov 6, 2013

Because you didn't write the code that render the login form.

open /vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Resources/views/Security/login.html.twig, copy the code in the fos_user_content block to your custom login.html.twig, reload the page, then you'll see the form.

If you want to customize the form, rewrite the code you've copied.