3

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.

ianp
  • 163
  • 12

1 Answers1

5

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 %}
Stephen Lewis
  • 2,429
  • 11
  • 17