Skip to main content
1 of 2
Peter Procházka
  • 9.5k
  • 2
  • 30
  • 71

You need to create your custom rule for this.

Create a class which inherits StringOperatorCondition:

using Sitecore;
using Sitecore.Rules;
using Sitecore.Rules.Conditions;

namespace ClientName.Foundation.SitecoreExtensions.Rules
{
    public class IsExperienceEditorMode<T> : StringOperatorCondition<T>
        where T : RuleContext
    {
        protected override bool Execute(T ruleContext)
        {
            return Context.PageMode.IsExperienceEditor;
        }
    }
}

You can even check whether somebody is editing by using Context.PageMode.IsExperienceEditorEditing instead.

You can also use Context.PageMode.IsPreview to check whether you are in preview instead of checking whether you are in Experience Editor.

Decompile with ilSpy or dotPeek Sitecore.Kernel.dll and go to Sitecore namespace and under Context, there is PageMode and various other modes that use can check:

enter image description here

Peter Procházka
  • 9.5k
  • 2
  • 30
  • 71