0

如果配置不正确,我想在渲染预览中显示内容警告。它应该只对登录的内容管理员可见。

有没有办法在模板中知道它是登录用户还是渲染预览?

作为一个基本思想:

{% if menu.root_uuid %}
    <!-- do amazing things -->
{% elseif is_render_preview() %}
    <div class="warning">
        The menu can not be displayed, because no root folder is selected.
    </div>
{% endif %}

4

1 回答 1

2

控制器被赋予一个$preview属性以知道它是否是预览。在 twig 中没有变量,但您可以通过以下方式访问控制器属性:

{% if app.request.attributes.get('preview') %}
    {# do something only for preview #}
{% endif %}
于 2019-05-15T04:47:36.063 回答