World is now on Opti ID! Learn more

Linus Ekström
Feb 3, 2014
  19946
(9 votes)

The three rendering modes of EPiServer

When a template is rendered for a content item in EPiServer, items might be rendered a bit different depending of which “mode” the request is done for. The three modes are:

  1. Default (normal site visitor).
  2. Edit (On Page Editing).
  3. Preview (preview within the User Interface).

A common request from partners is to be able to determine if the current request is for an page that is done to enable on page editing. For this reason, the property EPiServer.Editor.PageEditing.PageIsInEditMode was introduced together with the all new On Page Editing in EPiServer 7. Though still property is still available and valid in EPiServer 7.5, it is now possible to determine the exact “mode” for the current request through EPiServer’s routing API and the property EPiServer.Web.Routing.Segments.RequestSegmentContext.CurrentContextMode which returns an instance of the enum EPiServer.Web.ContextMode.

Let’s determine the results for these methods/properties in the different modes with a simple template for the start page of the site:

URL for current content: <strong><%=EPiServer.Web.Routing.UrlResolver.Current.GetUrl(CurrentPage.ContentLink) %></strong><br />
PageEditing.PageIsInEditMode: <strong><%= EPiServer.Editor.PageEditing.PageIsInEditMode %></strong><br />
RequestSegmentContext.CurrentContextMode: <strong><%= EPiServer.Web.Routing.Segments.RequestSegmentContext.CurrentContextMode %></strong>

 

Site view

Default

Editorial view

Edit

Preview in UI

Preview

Getting a URL for a specific mode

As some people have mentioned in the forums, getting a URL for an item will produce different formats when viewing an item on the site and when editing it (as can be viewed in the images above). If you want to always create a URL for a given mode regardless of the current request, this can be done by calling an overload of the GetUrl-method of the UrlResolver:

string language = null;
var iLocalizable = CurrentPage as ILocalizable;
if (iLocalizable != null && iLocalizable.Language != null)
{
    language = iLocalizable.Language.Name;
}
 
var deterministicUrl = UrlResolver.Current.GetUrl(CurrentPage.ContentLink, language, new VirtualPathArguments() { ContextMode = ContextMode.Default });
Feb 03, 2014

Comments

Jeff Wallace
Jeff Wallace Feb 5, 2014 06:41 PM

Good stuff!

Mar 12, 2014 10:57 PM

Nice :)

Andrew Sanin
Andrew Sanin Jan 14, 2015 11:18 AM

Very helpful!

Please login to comment.
Latest blogs
Password protect your Optimizely CMS content

Want to share some private content on your website with basic password protection? You can do this with an Optimizely form and Audience based...

Brian Gerby | Jul 17, 2025 |

Importing Form Submission Data into Optimizely Forms Using DdsPermanentStorage

Recently, we needed to import a large number of records from a third-party system into Optimizely Forms . The data was available in CSV format, and...

Pawan Singh | Jul 16, 2025

Cancelling CMS Scheduled Jobs

From flags to tokens: making Optimizely CMS scheduled jobs more elegant with .NET cancellation tokens.

Damian Smutek | Jul 16, 2025 |

Optimizely Frontend Hosting: Deploy Without PowerShell Using the @kunalshetye/opticloud Package

In my last two blog posts, I walked through how to get started with deploying a headless app to Optimizely Frontend Hosting using PowerShell and th...

Szymon Uryga | Jul 15, 2025

New Administrator Certifications Are Here — 7 Ways to Get Certified with Optimizely

Not a developer but want to prove your product expertise? We’ve got great news. We’re thrilled to announce the expansion of Optimizely’s...

Satata Satez | Jul 15, 2025

Optimizely London Dev Meetup 10th July 2025

Overview & Agenda As 2025 rolled around this year it was time for another one of our much beloved developer meetups in London. This year, I took us...

Scott Reed | Jul 15, 2025