Sulu CMS升级后预览中不存在意外变量错误

Unexpected Variable does not exist Error in Preview after Sulu CMS upgrade

我在内容块外的模板中定义了一些全局 twig 变量,现在升级到 sulu 2.0 后,这在预览中抛出意外 "Variable does not exist Error"。实际页面呈现仍然完好无损。在 @JohannesWachter 的评论之后,它出现了,预览现在只渲染内容块并忽略外部变量。

我有以下(简化的)代码,它曾经在 sulu 1.6 中工作: main.html.twig

{% extends "base.html.twig" %}

{% set hasContent = content is defined %}

{% if hasContent %}
    {% set headline = content.headline is defined and content.headline ? content.headline : content.title %}
{% endif %}

{% block content %}
        <div class="row">

            {% block row %}
                <section class="col-sm-8 main-content">
                    {% if hasContent and headline is defined%}
                        <h1 class="headline" property="title">{{ headline }}</h1>
                    {% endif %}

在预览中,{% if hasContent and headline is defined%} 行出现以下错误:变量 "hasContent" 不存在。 (main.html.twig 第 43 行)

有没有办法在 sulu 2.0 的预览和主页中提供这种全局变量?

我通过将内容块中使用的变量移动到内容块中来修复它:

{% extends "base.html.twig" %}

{# set variables nesessary to adjust base.html.twig only #}

{% block content %}
    {% set hasContent = content is defined %}

    {% if hasContent %}
        {% set headline = content.headline is defined and content.headline ? content.headline : content.title %}
    {% endif %}

        <div class="row">

            {% block row %}
                <section class="col-sm-8 main-content">
                    {% if hasContent and headline is defined%}
                        <h1 class="headline" property="title">{{ headline }}</h1>
                    {% endif %}

我尝试将变量定义移动到 setup.html.twig 文件中,但仅在包含的模板内定义的变量不再对外部可见。