An Independent Sitecore Learning Resource

Menu

Code Gotcha: Sitecore Versions and 'IsExperienceEditor' Context

Code Gotcha: Sitecore Versions and 'IsExperienceEditor' Context

Author

Brandon Bruno

Published

5/16/2017

Tags

Sometimes the Little Stuff Matters

Do you have view markup in Sitecore that has this type of code?

	
@if (Sitecore.Context.IsPageEditor)
{
	<div>This is only shown in the Page Editor or Experience Editor!</div>
}
	

For those not in the know, the Sitecore.Context.IsPageEditor property is a boolean value that determines if the current page is being viewed in the Page Editor. In keeping up with the new name of "Experience Editor" in Sitecore 8, Sitecore 8.1 introduced IsExperienceEditor in code. Both function exactly the same way.

As it turns out, however, IsExperienceEditor does not work in all versions of 8.1 - it wasn't introduced until Sitecore 8.1 Update 1.

I recently worked on a small code demo for a client and got caught up in this Sitecore versioning issue. I was updating to the newer Experience Editor properties, but was caught off guard when my views were failing to compile. To verify my issue, I drilled into the DLLs of several Sitecore verions until I saw the change for myself. IsExperienceEditor is new in revision 151207 and IsPageMode has been properly marked as "Obsolete":

Left: Sitecore 8.1 Initial Release (rev 151003). Right: Sitecore 8.1 Update 1 (rev 151207).

So there you have it - don't start updating your views to use the IsExperienceEditor code until you're running Sitecore 8.1 Update 1 (rev 151207) everywhere you need it.

Do you have questions or comments about this post? Find me on Twitter: @SitecoreSpark