Search code examples
sitecorecompatibilitysitecore8

Sitecore IsPageEditor and IsExperienceEditor


We are currently writing a module for Sitecore and have ran into a problem.

We have a pipeline in which we do the following check:

if (Sitecore.Context.PageMode.IsExperienceEditor)
{
     return;
}

The problem is that one of our clients are running and older version of Sitecore (8.0 update 5) where the property IsExperienceEditor does not exist yet. See Sitecore release notes for next update where it is introduced.

To quickly fix the error we used the older deprecated property which is this:

if (Sitecore.Context.PageMode.IsPageEditor)
{
     return;
}

Now the question is, is there any way in which we can test for the Sitecore version so we can have backwards compatibility in the module?


Solution

  • You can use the code which is executed in Sitecore in background of both properties mentioned by you:

    if (Sitecore.Context.Site.DisplayMode == Sitecore.Sites.DisplayMode.Edit)
    {
        return;
    }
    

    I know that using Sitecore.Context.PageMode.IsExperienceEditor (or Sitecore.Context.PageMode.IsPageEditor) is more elegant, but in a situation when you need to support both old and new Sitecore versions, that's sounds like a good option.