Thursday, 4 September 2025

Preview Unpublished Pages and Blocks on the Frontend (Optimizely CMS 12)

Introduction

In my previous post, I explained how to customize the ContentArea rendering pipeline in Optimizely CMS 12 so editors can see unpublished block content while previewing pages in the CMS.

That approach works great inside the CMS UI (Edit/Preview mode). But what if you want to enable the same functionality on the front-end site, using a simple query string flag?

That’s where the ?showdrafts=true parameter comes in.

The Problem

By default, Optimizely only shows published content when you browse a site page directly. Even if a page has a saved draft version (with new or updated blocks), you won’t see it on the public site unless the draft is published.

  • The page instance returned by routing is the published version.
  • The ContentAreaRenderer filters unpublished items before rendering.

As a result, any unpublished blocks in a draft page are invisible.

The Approach

We need three things working together:

  1. Detect ?showdrafts=true.
  2. Load the draft page version instead of the published one.
  3. Render all ContentArea items (published + unpublished) so draft blocks are not filtered out.

Step 1: Helper to Fetch Draft Pages


Step 2: Ensure Draft Blocks Render Too


Override ContentAreaRenderer to skip the internal filtering step when showdrafts=true.

Step 3: Controller Example


Final Result

  • Default URL /about-us → shows published page + published blocks.
  • With ?showdrafts=true → loads the draft page (so unpublished block references are included) and renders them.
  • Works consistently both inside CMS preview and on the public site (for editors/admins).

Closing Thoughts

The ?showdrafts=true query parameter is a simple but powerful way to let editors verify draft content directly on the site without switching to CMS preview.

When combined with the approach from my earlier post, you now have full control over showing unpublished content both inside and outside the CMS interface.

Just remember: never expose drafts to anonymous visitors — always enforce role checks.

About the Author

Adnan Zameer, Lead Developer at Optimizley UK, is a certified Microsoft professional, specializing in web app architecture. His expertise includes Optimizley CMS and Azure, showcasing proficiency in crafting robust and efficient solutions.

0 comments :

Post a Comment