I've come across countless questions about FOSUserBundle's overriding possibilities, and discovered some "design incoherence" in their use of Twig's inheritance mechanisms, which I'd like to clarify as it is really disturbing in some projects...
Overriding a template in FOSUserBundle
From what I've read, here's how we should override a template. Let's say, the login template (Security/login.html.twig). First, I need to override the global FOSUser layout (layout.html.twig').
Global FOSUser layout
{% extends "::layout.html.twig" %}
{% block title %}Page title{% endblock title %}
{% block body %}
<div id="container">
{% block fos_user_content %}{% endblock %}
</div>
{% endblock body %}
The title and body blocks are references to the HTML <title> and <body> tags (globally). Now, when it comes to the login itself, here's what I've written.
Login form
{% extends "MyUserBundle::layout.html.twig" %}
{% block fos_user_content %}
{% if error %}
<div class="error">{{ error|trans({}, 'FOSUserBundle') }}</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({}, 'FOSUserBundle') }}</label>
<input type="text" id="username" name="_username" value="{{ last_username }}" required="required" /><br />
<label for="password">{{ 'security.login.password'|trans({}, 'FOSUserBundle') }}</label>
<input type="password" id="password" name="_password" required="required" /><br />
<input type="checkbox" class="checkbox" id="remember_me" name="_remember_me" value="on" />
<label for="remember_me">{{ 'security.login.remember_me'|trans({}, 'FOSUserBundle') }}</label><br />
<label for="_submit"></label>
<input type="submit" class="submit" id="_submit" name="_submit" value="{{ 'security.login.submit'|trans({}, 'FOSUserBundle') }}" />
</form>
{% endblock fos_user_content %}
Now, here's what I automatically understand : the layout creates an environment, and other templates are "included" into the fos_user_content block. The result for the login page follows this scheme.
Another try ? Registration.
Now, following this pattern, I tried to extend the registration form thinking : "I should extend the content of the fos_user_content just like I did before! Guess what? That's not it! Here's my Registration/register_content.html.twig file.
Register form content
{% extends "MyUserBundle::layout.html.twig" %}
{% block fos_user_content %}
<form action="{{ path('fos_user_registration_register') }}" {{ form_enctype(form) }} method="POST" class="fos_user_registration_register">
{{ form_widget(form) }}
<div>
<input type="submit" value="{{ 'registration.submit'|trans({}, 'FOSUserBundle') }}" />
</div>
</form>
{% endblock %}
Problem
The previous pattern does not seem to apply to the Registration part : when I follow the same scheme, my registration page is graphically doubled. The form is printed twice, the titles as well, and so on... Just like I had done a unnecessary include/inheritance somewhere...
Does anyone have any idea with FOSUserBundle isn't designed with a universal pattern for overriding templates ? Why do I need to rebuild the complete inheritance tree to have a similar display on both the login, and the registration form ?
Solution (?)
Cerad's answer gives a different scheme for the registration case. The Twig inheritance tree excludes register_content.html.twig, and uses register.html.twig. When you have a look at this file, you can see it simply... includes register_content.html.twig. This is the incoherence I'm talking about. Why is this ? Why not use a single file with the content, directly ? Why is it that FOS decided to add this useless (?) include step ?