0

I would like to display a content warning in the render preview, if something is not configured correctly. It should only be visible to logged in content managers thou.

Is there a way to know in the template, if it is a logged in user or a render preview?

as a basic idea:

{% 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 %}

Andreas
  • 1,691
  • 1
  • 15
  • 34

1 Answers1

3

The controller is given a $preview attribute to know if its a preview or not. In twig there is no variable but you can access controller attributes the following way:

{% if app.request.attributes.get('preview') %}
    {# do something only for preview #}
{% endif %}
Alexander Schranz
  • 2,154
  • 2
  • 25
  • 42