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 useyou can check and use:
You also need to create this rule in Sitecore.
Do it under /sitecore/system/Settings/Rules/Definitions/Elements/ClientName/
or anywhere under /sitecore/system/Settings/Rules/Definitions/Elements/
.
Create new item based on /sitecore/templates/System/Rules/Condition
template.
Text would be "where in Experience Editor mode" or anything else you like.
Type will be classname with namespace with assembly name specified like ClientName.Foundation.SitecoreExtensions.Rules.IsExperienceEditorMode, ClientName.Foundation.SitecoreExtensions
.
Here you have it as picture: