Is there any way of adding a class onto a page body when it is viewed within the 'live preview' pane?

I can then use this to make things either show or not show.

I want to do this to highlight specific things to content editors that I don't feel are worth highlighting to regular users.

I think I can only do this by hanging rules off a special 'preview only' class.


Craft's Request service has a built-in method for this, isLivePreview.

Here's how to only display content in the live preview view:

{% if craft.request.isLivePreview %}
    <p>Only appears in live preview.</p>
{% endif %}
  • Spot on. Cheers.
    – ianp
    Apr 6 '17 at 17:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.