How to detect Page Editor mode in Sitecore through code

f you are a Sitecore developer then definitely in many instances you would need to show or hide some components in the Page Editor mode. So How to detect Page Editor mode in Sitecore through code?

There are many ways to detect the page editor mode in Sitecore using Javascript, with the help of cookies, query string etc. But let us look into the best approach to check the page editor mode using server side and client site.

How to detect Page Editor mode in Sitecore Programmatically?

The best and simple approach is to get the information using Sitecore.Context.PageMode. If the site is being viewed in the PageEditor mode then you could easily enable or disable the components with the help of a condition.

if (Sitecore.Context.PageMode.IsPageEditorEditing) –To check if it is Page Editor mode
if (Sitecore.Context.PageMode.IsNormal) – To check if it is normal page use
if (Sitecore.Context.PageMode.IsPreview) – To check if it is preview mode use

Other Sitecore PageModes

  • IsPageEditorClassic
  • IsPageEditorDesigning
  • IsPageEditorEditing
  • IsPageEditorNavigating

Detecting Sitecore PageEditor Mode In JavaScript

In case if you would like to detect PageEditor mode in client side using the JavScript, then below code should help you in detecting if the user is using the Page editor mode or normal mode.

 

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *