Detect Preview or Channel Manager Request Context

Introduction

Goal

Detect whether a page is requested in the context of a preview site or the Experience manager.

Background

In your template, you might want to only include some HTML if the request is for a preview version of the site, or when the request is from the Experience manager.

Methods

HstRequestContext provides the following methods to determine preview state:

  • isPreview()
    Returns true when accessing preview content through a preview mount, i.e. any HST mount which has the property hst.type set to preview. This includes but is not limited to Experience manager requests.
  • isChannelManagerPreviewRequest()
    Returns true when accessing preview content through the Experience manager.

Examples

You can use the above methods within a JSP template as follows:

<hst:defineObjects/>
<c:set var="isPreview" value="${hstRequest.requestContext.preview}"/>
<c:set var="isChannelManagerPreviewRequest" value="${hstRequest.requestContext.channelManagerPreviewRequest}"/>

Or in a Freemarker template:

<@hst.defineObjects/>
<#assign isPreview=hstRequest.requestContext.preview/>
<#assign isChannelManagerPreviewRequest=hstRequest.requestContext.channelManagerPreviewRequest/>
Did you find this page helpful?
How could this documentation serve you better?
On this page
    Did you find this page helpful?
    How could this documentation serve you better?