扩展布局的时候一定要写fos_user_content的内容吗?

Do we have to write the content of the fos_user_content when extending the layout?

您好,我正在尝试使用自定义表单进行用户注册: 在我的 layout.html.twig 中:

{% extends 'ProjectBundle::project.html.twig' %}
{% block content %}
    {% block fos_user_content %}{% endblock %}
{% endblock %}

表格显示正确。

现在我想自定义登录页面: 我创建了一个 Security/login.html.twig

内容是:

{% extends "FOSUserBundle::layout.html.twig" %}

但它不显示表格。 知道为什么吗?

以下是我组织事物的方式:

在app/Resources/FOSUserBundle/views/layout.html.twig :

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

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

然后,如果您想自定义登录页面,例如,您输入 app/Resources/FOSUserBundle/views/Security/login.html.twig(与供应商 fosuser 中的架构相同):

{% extends "FOSUserBundle::layout.html.twig" %}

{% block fos_user_content %}

{# Your overriding template of the login view (containing the essential lines taken from the fox user view of the vendor, especially the ones displaying the form #}

{% endblock fos_user_content %}

所以我猜你可能忘记了这些 "essential" 行在你自己的登录模板中显示表单

您可以在此处找到更多相关信息: https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/overriding_templates.md

希望对你有所帮助...:)