Detecting Preview Mode in Twig Templates


Detecting preview mode can be useful to conditionally change frontend behavior - e.g., disabling popups or tracking when editing page content.

🛠️ How to Check for Preview Mode

There are two recommended ways to detect if a page is in preview mode:

1. _preview_token Query Parameter

When a page is loaded in preview mode, it includes the _preview_token query string.
You can check for this in a controller or directly in your Twig template logic:
1{% if app.request.get('_preview_token') is not null %} 2 {# Show preview-specific logic #} 3{% endif %} 4

2. isPreview Twig Variable

The isPreview variable is automatically passed to the @FiftyDegSyliusDegditorBasePlugin/shop/page.html.twig template.
You can use it directly in your templates like this:
1{% if isPreview %} 2 {# Show preview-specific logic #} 3{% endif %} 4
This is the recommended method when you're working inside the standard DegDitor rendering flow.
Three, two, one...

Ready for DegDitor?

Try the plugin

Experience the best features at no cost

Get a better understanding of DegDitor and how it works

Test it risk-free and see the results

Try it

Get a demo

Get a personalized demo tailored to your unique needs

Preview our pricing plans

Evaluate DegDitor against your requirements

Get a demo

We are here for you

After months of intense development, it’s time to put DegDitor to work. For feedback, questions or information please contact us!

Contact us