Sitecore IsPageEditor and IsExperienceEditor

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

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

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

      

The problem is that one of our clients is running and an old version of Sitecore (8.0 update 5) where the IsExperienceEditor property doesn't exist yet. See the Sitecore release notes for the next update where it is presented.

To quickly fix the error, we used a deprecated deprecated property:

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

      

Now the question is, is there a way to check the Sitecore version so that we can have backward compatibility in the module?

+3


source to share


2 answers


You can use code that runs in the background in Sitecore on both of the properties you specify:

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

      



I know using is Sitecore.Context.PageMode.IsExperienceEditor

(or Sitecore.Context.PageMode.IsPageEditor

) more elegant, but in a situation where you need to support both old and new versions of Sitecore, this sounds like a good option.

+3


source


The deprecated property IsPageEditor

is still present specifically for backward compatibility. IsExperienceEditor

is just a renamed property that does the same thing as IsPageEditor

.

However, you can check for a property like this:



public static bool HasProperty(this object obj, string propertyName)
{
    return obj.GetType().GetProperty(propertyName) != null;
}

      

Another option is to create two different versions of a module if the implementation is significantly different for different Sitecore versions.

0


source







All Articles