Search code examples
sulu

Sulu CMS: Is there a way to see in the template, weather it is a render preview?


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


Solution

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