2017-06-29 56 views
3

我们正在为Sitecore编写一个模块,并且遇到了问题。Sitecore IsPageEditor和IsExperienceEditor

我们有一个管道中,我们做以下检查:

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

的问题是,我们的一位客户正在运行和旧版本Sitecore的的(8.0更新5),其中财产IsExperienceEditor不存在然而。请参阅Sitecore release notes进行下一次更新。

快速修复,我们使用了旧的过时属性,该属性是这样的错误:

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

现在的问题是,有没有什么办法,使我们可以测试Sitecore的版本,所以我们可以有向后兼容性在模块中?

回答

3

您可以使用它在Sitecore的由你提到的这两个特性的后台执行的代码:

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

我知道,使用Sitecore.Context.PageMode.IsExperienceEditor(或Sitecore.Context.PageMode.IsPageEditor)更优雅,但在一种情况,当你需要以支持旧版和新版Sitecore版本,这听起来像是一个不错的选择。

+0

感谢这似乎工作。 –

0

IsPageEditor的不推荐使用的属性仍然专门用于向后兼容的目的。 IsExperienceEditor只是一个重命名的属性,它的作用与IsPageEditor一样。

但是,您可以检查一个属性是否存在这样的:

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

另一种选择是使两个不同版本的模块,如果实现变得不同版本Sitecore的的显著不同。