【问题标题】:ezpublish/symfony renders 404 in Smarty, everything else in Twigezpublish/symfony 在 Smarty 中呈现 404,在 Twig 中呈现其他所有内容
【发布时间】:2014-06-18 08:24:04
【问题描述】:

在我的 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 页面,但是这个页面没有被调用

【问题讨论】:

  • 您是处于开发模式还是生产模式?
  • 两种模式都是一样的

标签: php symfony smarty twig ezpublish


【解决方案1】:

先添加这个配置参数

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

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

这会将位于 path/to/yourbundle/Resources/views/pagelayout_legacy.html.twig 中的 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-11
    • 2021-08-08
    • 2021-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-17
    相关资源
    最近更新 更多