Take the community feedback survey now.

Linus Ekström
Feb 3, 2014
  20190
(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
A day in the life of an Optimizely Developer - We Hacked the Future: Netcel's Opal Hackathon Adventure

Ever wondered what happens when you mix  AI ,  creativity , and a dash of competitive spirit? Welcome to the  Opal Hackathon 2025 —where we rolled ...

Graham Carr | Aug 31, 2025

Simple Feature Flags In Optimizely CMS

The Problem I was working with a CMS 11 client who wanted to introduce two new third party content sources. These would be synchronized into new...

Mark Stott | Aug 31, 2025

SQL addon for Optimizely CMS 12 updated with new features

First released in 2021, the SQL Studio addon for Optimizely CMS lets you query your database directly from the edit UI. The latest update adds...

Tomas Hensrud Gulla | Aug 29, 2025 |

🎓 New Certification Icons Are Now Live on World!

If you’ve passed an Optimizely Academy certification, you’ll now see something new beside your name on World —  fresh certification icons are live...

Satata Satez | Aug 29, 2025

Opalytics Under the Hood – How I wired Piwik PRO into Opal with .NET and JSON

In the previous post , I showed how Opalytics lets you ask human questions and get analytics answers. This time we’re going full dev-mode: OAuth...

Allan Thraen | Aug 28, 2025 |

Understanding Optimizely CMS 12 Base Classes and Common Interfaces

Optimizely CMS 12 is built around a powerful and flexible content model. By understanding the core base classes and interfaces, developers can buil...

Pär Wissmark | Aug 28, 2025 |