Symfony异常页面上的细枝模板未呈现头部

Symfony异常页面上的细枝模板未呈现头部,symfony,twig,Symfony,Twig,我有一些小树枝模板的问题 我在app/TwigBundle/上复制了TwigBundle,使其过载。 现在我想自定义我的404页为例。我不知道为什么,但是我已经从视图中获得了所有HTML代码,很好的布局,但是主布局的头部是空的,所以这不会加载任何CSS文件或JS 在所有其他页面中,所有工作都会找到,此问题仅从异常视图中出现 我的架构: error404.html.twig(扩展)->layout-public-user.html.twig(重载内容块)->layout.html.twig(包括)

我有一些小树枝模板的问题

我在app/TwigBundle/上复制了TwigBundle,使其过载。 现在我想自定义我的404页为例。我不知道为什么,但是我已经从视图中获得了所有HTML代码,很好的布局,但是主布局的头部是空的,所以这不会加载任何CSS文件或JS

在所有其他页面中,所有工作都会找到,此问题仅从异常视图中出现

我的架构:

error404.html.twig(扩展)->layout-public-user.html.twig(重载内容块)->layout.html.twig(包括)->head.html.twig

查看404:

{# 
APP > TwigBundle > Exceptions > error404.html
#}

{% extends "::layout-public-v2.html.twig" %}

{% block title %}Erreur 404 (page non trouvée) - {{ parent() }}{% endblock %}
//blablablabla
{# 
APP > layout-public-v2.html
variables : view_content
#}

{% block topBar %}
{% include '::topbar/topbar-public-v2.html.twig' %}
{% endblock %}

<section id="content">
{% block body %}

 {{ view_content|raw }}
{% endblock %}
</section>
{# 
    APP > layout.html
#}

{% include '::header/header-v2.html.twig' %}

<body class="">
{% block topBar %}
{% endblock %}

{% if app.user %}
    {% include '::layout-user-v2.html.twig' with {'view_content': block('content')} %}
{% else %}
    {% include '::layout-public-v2.html.twig' with {'view_content': block('content')} %}
{% endif %}

{% include '::footer/footer-js-v2.html.twig' %}

</body>
{# 
  APP > header/header-v2.html
#}

<!DOCTYPE html>
<html lang="fr" class="app">
<head>
  {% block head %}
    <meta charset="utf-8" />
    <title>JobaPic</title>
    <meta name="description" content="app, web app, responsive, admin dashboard, admin, flat, flat ui, ui kit, off screen nav" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" /> 
    {% include '::header/header-css-v2.html.twig' %}
    <!--[if lt IE 9]>
      <script src="{{ asset('bundles/general/js/ie/html5shiv.js') }}"></script>
      <script src="{{ asset('bundles/general/js/ie/respond.min.js') }}"></script>
      <script src="{{ asset('bundles/general/js/ie/excanvas.js') }}"></script>
    <![endif]-->
  {% endblock %}
</head>
布局公共:

{# 
APP > TwigBundle > Exceptions > error404.html
#}

{% extends "::layout-public-v2.html.twig" %}

{% block title %}Erreur 404 (page non trouvée) - {{ parent() }}{% endblock %}
//blablablabla
{# 
APP > layout-public-v2.html
variables : view_content
#}

{% block topBar %}
{% include '::topbar/topbar-public-v2.html.twig' %}
{% endblock %}

<section id="content">
{% block body %}

 {{ view_content|raw }}
{% endblock %}
</section>
{# 
    APP > layout.html
#}

{% include '::header/header-v2.html.twig' %}

<body class="">
{% block topBar %}
{% endblock %}

{% if app.user %}
    {% include '::layout-user-v2.html.twig' with {'view_content': block('content')} %}
{% else %}
    {% include '::layout-public-v2.html.twig' with {'view_content': block('content')} %}
{% endif %}

{% include '::footer/footer-js-v2.html.twig' %}

</body>
{# 
  APP > header/header-v2.html
#}

<!DOCTYPE html>
<html lang="fr" class="app">
<head>
  {% block head %}
    <meta charset="utf-8" />
    <title>JobaPic</title>
    <meta name="description" content="app, web app, responsive, admin dashboard, admin, flat, flat ui, ui kit, off screen nav" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" /> 
    {% include '::header/header-css-v2.html.twig' %}
    <!--[if lt IE 9]>
      <script src="{{ asset('bundles/general/js/ie/html5shiv.js') }}"></script>
      <script src="{{ asset('bundles/general/js/ie/respond.min.js') }}"></script>
      <script src="{{ asset('bundles/general/js/ie/excanvas.js') }}"></script>
    <![endif]-->
  {% endblock %}
</head>
{#
APP>layout-public-v2.html
变量:查看内容
#}
{%block topBar%}
{%include'::topbar/topbar-public-v2.html.twig%}
{%endblock%}
{%block body%}
{{查看内容{124;原始}}
{%endblock%}
布局:

{# 
APP > TwigBundle > Exceptions > error404.html
#}

{% extends "::layout-public-v2.html.twig" %}

{% block title %}Erreur 404 (page non trouvée) - {{ parent() }}{% endblock %}
//blablablabla
{# 
APP > layout-public-v2.html
variables : view_content
#}

{% block topBar %}
{% include '::topbar/topbar-public-v2.html.twig' %}
{% endblock %}

<section id="content">
{% block body %}

 {{ view_content|raw }}
{% endblock %}
</section>
{# 
    APP > layout.html
#}

{% include '::header/header-v2.html.twig' %}

<body class="">
{% block topBar %}
{% endblock %}

{% if app.user %}
    {% include '::layout-user-v2.html.twig' with {'view_content': block('content')} %}
{% else %}
    {% include '::layout-public-v2.html.twig' with {'view_content': block('content')} %}
{% endif %}

{% include '::footer/footer-js-v2.html.twig' %}

</body>
{# 
  APP > header/header-v2.html
#}

<!DOCTYPE html>
<html lang="fr" class="app">
<head>
  {% block head %}
    <meta charset="utf-8" />
    <title>JobaPic</title>
    <meta name="description" content="app, web app, responsive, admin dashboard, admin, flat, flat ui, ui kit, off screen nav" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" /> 
    {% include '::header/header-css-v2.html.twig' %}
    <!--[if lt IE 9]>
      <script src="{{ asset('bundles/general/js/ie/html5shiv.js') }}"></script>
      <script src="{{ asset('bundles/general/js/ie/respond.min.js') }}"></script>
      <script src="{{ asset('bundles/general/js/ie/excanvas.js') }}"></script>
    <![endif]-->
  {% endblock %}
</head>
{#
APP>layout.html
#}
{%include'::header/header-v2.html.twig%}
{%block topBar%}
{%endblock%}
{%if-app.user%}
{%include'::layout-user-v2.html.twig'和{'view\u content':block('content')}%}
{%else%}
{%include'::layout-public-v2.html.twig'带有{'view_content':block('content')}%}
{%endif%}
{%include'::footer/footer-js-v2.html.twig%}
标题:

{# 
APP > TwigBundle > Exceptions > error404.html
#}

{% extends "::layout-public-v2.html.twig" %}

{% block title %}Erreur 404 (page non trouvée) - {{ parent() }}{% endblock %}
//blablablabla
{# 
APP > layout-public-v2.html
variables : view_content
#}

{% block topBar %}
{% include '::topbar/topbar-public-v2.html.twig' %}
{% endblock %}

<section id="content">
{% block body %}

 {{ view_content|raw }}
{% endblock %}
</section>
{# 
    APP > layout.html
#}

{% include '::header/header-v2.html.twig' %}

<body class="">
{% block topBar %}
{% endblock %}

{% if app.user %}
    {% include '::layout-user-v2.html.twig' with {'view_content': block('content')} %}
{% else %}
    {% include '::layout-public-v2.html.twig' with {'view_content': block('content')} %}
{% endif %}

{% include '::footer/footer-js-v2.html.twig' %}

</body>
{# 
  APP > header/header-v2.html
#}

<!DOCTYPE html>
<html lang="fr" class="app">
<head>
  {% block head %}
    <meta charset="utf-8" />
    <title>JobaPic</title>
    <meta name="description" content="app, web app, responsive, admin dashboard, admin, flat, flat ui, ui kit, off screen nav" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" /> 
    {% include '::header/header-css-v2.html.twig' %}
    <!--[if lt IE 9]>
      <script src="{{ asset('bundles/general/js/ie/html5shiv.js') }}"></script>
      <script src="{{ asset('bundles/general/js/ie/respond.min.js') }}"></script>
      <script src="{{ asset('bundles/general/js/ie/excanvas.js') }}"></script>
    <![endif]-->
  {% endblock %}
</head>
{#
APP>header/header-v2.html
#}
{%block head%}
乔巴奇
{%include'::header/header-css-v2.html.twig%}
{%endblock%}
标题css

{# 
  APP > header/header-css-v2.html
#}

<link rel="stylesheet" href="{{ asset('bundles/general/css/bootstrap.css') }}" type="text/css" />
<link rel="stylesheet" href="{{ asset('bundles/general/css/animate.css') }}" type="text/css" />
<link rel="stylesheet" href="{{ asset('bundles/general/css/font-awesome.min.css') }}" type="text/css" />
<link rel="stylesheet" href="{{ asset('bundles/general/css/font.css') }}" type="text/css" />
<link rel="stylesheet" href="{{ asset('bundles/general/js/calendar/bootstrap_calendar.css') }}") type="text/css" />
<link rel="stylesheet" href="{{ asset('bundles/general/css/app.css') }}" type="text/css" />
{#
APP>header/header-css-v2.html
#}

谢谢

我认为您应该首先扩展
layout.html
,其中包括
public layout.html
;但是您首先要扩展
public layout.html


问题似乎是您扩展的方式,因为{%block topbar%}似乎被空块覆盖了

您能否提供细枝源(至少是您可能使用的资产)?您创建异常细枝文件的确切路径是什么?我已经编辑并为您提供了细枝模板源。我的404页面的确切路径是:app/resources/TwigBundle/views/Exception/error404.html.twigf如果您获得了输出的视图源,是否看到了包含的标题css/js?如果是,请检查路径是否正确。正如您所知,扩展或包含文件(例如,
::blahblah.html.twig
)的路径应该是app/Resources/views/blahblah.html.twigNo,我用chrome工具栏检查DOM,标记是空的……我认为您应该首先扩展layout.html,其中包括public-layout.html;但您说过首先要扩展public-layout.html。问题似乎在于扩展的方式,因为
{%block topbar%}
似乎被空块覆盖了