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:
- Detect
?showdrafts=true
. - Load the draft page version instead of the published one.
- 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.
0 comments :
Post a Comment