Symfony Server crashes when extending FOSUserBundle's default template layout.html.twig

老子叫甜甜 提交于 2019-12-02 03:30:23

When you override standart FOSUser layout you need to place your layout into app/Resources/FOSUserBundle/views/layout.html.twig. great, you did this. it's just a layout, it should not extend standart FOSUser layout, so remove line {% extends 'FOSUserBundle::layout.html.twig' %}. But usually developers make one base layout, in my case it is \app\Resources\views\base.html.twig, so if I want to override fosuser layout I will have in app/Resources/FOSUserBundle/views/layout.html.twig something like this

{% extends 'base.html.twig' %}

{% block title %}User Management{% endblock %}

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

In first line you extend your base layout not FOSUser. You may not extend something, maybe you have separate complete layout for this template.

The crash does make sense.

When you write:

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

The Symfony will first try to load app/Resources/FOSUserBundle/views/layout.html.twig. Failing to find the file will revert to similar path but inside the vendor directory. And if you are trying to extend FOS's template from within your FOS overriden template, that would create recursive loop:

app/Resource/FOSUserBundle/views/layout.html.twig 
^^ extends  
app/Resource/FOSUserBundle/views/layout.html.twig
^^ extends
app/Resource/FOSUserBundle/views/layout.html.twig
....
and so on...

So, this is not a way to solve the problem.

Make sure that your template is well placed in your app directory and not your bundle, as Denis Alimov suggested in a comment.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!