This article covers a Bloomreach Experience Manager version 13. There's an updated version available that covers our most recent release.

Detect Preview or Channel Manager Request Context

Introduction

Goal

Detect whether a page is requested in the context of a preview site or the channel 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 Channel 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 Channel Manager requests.
  • isCmsPreview()
    Returns true when accessing preview content through the Channel Manager.
    isCmsPreview() is deprecated as of version 13.2.0 and will be removed in 14.0.0. Use isChannelManagerPreviewRequest() instead.
  • isChannelManagerPreviewRequest()
    Returns true when accessing preview content through the Channel Manager.
    isChannelManagerPreviewRequest() is available from version 13.2.0 and replaces the deprecated isCmsPreview().

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="isCmsRequest" value="${hstRequest.requestContext.cmsRequest}"/>
<c:set var="isChannelManagerPreviewRequest" value="${hstRequest.requestContext.channelManagerPreviewRequest}"/>

Or in a Freemarker template:

<@hst.defineObjects/>
<#assign isPreview=hstRequest.requestContext.preview/>
<#assign isCmsRequest=hstRequest.requestContext.cmsRequest/>
<#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?