我在内容块之外的模板中定义了一些全局 twig 变量,现在升级到 sulu 2.0 后,这会在预览中引发意外的“变量不存在错误”。实际的页面渲染仍然完好无损。在@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 的预览版和主页中提供这种全局变量?