在我的eZ Publishe5站点上,我的所有模板都在vendor/ezsystems/demobundle/EzSystems/DemoBundle/Resources/views/子文件夹中的Twig中。他们都在我的整个网站上使用,没有问题。有一个例外: 404页。如果我转到mysite/nonexistingurl,它会给我一个kernel (20) / Error页面,状态为404。用于此的模板是eZ发布/symfony中的20.tpl,我不想要它,我想使用我自己的Twig模板。
我如何才能做到这一点?我添加了一个vendor/ezsystems/demobundle/EzSystems/DemoBundle/Resources/views/Exception/error.html.twig页面,但此页面未被调用
发布于 2014-08-19 17:01:20
首先添加此配置参数
parameters:
ezpublish_legacy.default.module_default_layout: 'YourBundle::pagelayout_legacy.html.twig'您可以将其添加到位于path/to/yourezpublishinstall/ezpublish/config中的parameters.yml文件中,parameters.yml通常导入位于同一文件夹中的config.yml中
这将把位于path/to/yourbundle/Resources/views/pagelayout_legacy.html.twig中的细枝模板定义为遗留堆栈模块模板的父模板
在pagelayout_legacy.html.twig模板中,您可以使用以下代码
{% extends 'YourBundle::pagelayout.html.twig' %}
{% block content %}
{# module_result variable is received from the legacy controller. #}
{% if module_result.errorCode is defined %}
<h1>{{ module_result.errorMessage }} ({{ module_result.errorCode }})</h1>
{% else %}
{{ module_result.content|raw }}
{% endif %}
{% endblock %}请注意,在代码中,模板扩展了pagelayout.html.twig模板,此处应定义一个名为content的块,pagelayout.html.twig通常可能是您的ez publish 5网站的主要基本布局。您可以根据需要修改pagelayout_legacy.html.twig模板
参考:http://share.ez.no/forums/developer/overriding-legacy-error-pages-templates
https://stackoverflow.com/questions/24280555
复制相似问题