Detect Preview or Channel Manager Request Context

Overview

This page explains how to determine if a page request is made in the context of a preview site or from the Experience manager (Channel Manager).

When to Use

Use these detection methods in your templates when you need to conditionally include HTML or logic based on whether the request is for a preview version of the site or originates from the Experience manager.

Methods

The HstRequestContext interface provides methods to identify the preview state of a request:

  • isPreview():
    Returns true if the request is for preview content through a preview mount. A preview mount is any HST mount with the property hst:type set to preview. This includes Experience manager requests, but is not limited to them.

  • isChannelManagerPreviewRequest():
    Returns true if the request is for preview content specifically through the Experience manager (Channel Manager).

Implementation Examples

JSP Template Example

Use the following code in a JSP template to set variables indicating the preview state:

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

Freemarker Template Example

Use the following code in a Freemarker template to assign variables for preview detection:

<@hst.defineObjects/> <#assign isPreview=hstRequest.requestContext.preview/> <#assign isChannelManagerPreviewRequest=hstRequest.requestContext.channelManagerPreviewRequest/>
Share Feedback
Page: /frontend/standard-components/jsp-code-to-find-out-whether-a-request-is-a-preview-or-cms-request
Section: Frontend
Category *