我在使用Twig模板时遇到了一些麻烦。
我通过在app / TwigBundle /上复制它来重载TwigBundle。 现在我想自定义我的404页面例如。我不知道为什么,但是我从视图中看到了所有HTML代码,布局很好,但主要布局的头部是空的,所以这个不加载任何CSS文件或JS!
在所有其他页面中,所有工作都找到,此问题仅出现在异常视图中!
我的架构:
error404.html.twig(extends) - > layout-public-user.html.twig(重载内容块) - > layout.html.twig(include) - > 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>
标题-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" />
由于
答案 0 :(得分:1)
我认为您应首先扩展layout.html
内部包含public-layout.html
的内容;但是你首先要扩展public-layout.html
问题似乎是你扩展的方式,因为似乎{%block topbar%}被空块重叠