0

在我的 eZ publish 5 站点上,我的所有模板都在 Twig 中,位于 vendor/ezsystems/demobundle/EzSystems/DemoBundle/Resources/views/ 子文件夹中。它们都在我的整个站点中使用,那里没有问题。除了一个例外:404 页。如果我转到 mysite/nonexistingurl,它会给我一个内核 (20) / 错误页面,状态为 404。用于此的模板是 eZ publish/symfony 中某处的 20.tpl,我不想要那个,我想为此使用我自己的 Twig 模板。

我怎样才能做到这一点?我添加了一个 vendor/ezsystems/demobundle/EzSystems/DemoBundle/Resources/views/Exception/error.html.twig 页面,但是这个页面没有被调用

4

1 回答 1

0

首先添加这个配置参数

parameters:
    ezpublish_legacy.default.module_default_layout: 'YourBundle::pagelayout_legacy.html.twig'

您可以将其添加到位于 的parameters.yml文件中path/to/yourezpublishinstall/ezpublish/configparameters.yml通常会在config.yml位于同一文件夹中的文件中导入

这会将位于的 twig 模板定义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

于 2014-08-19T09:01:19.753 回答