Building a Sitecore personalization rule with multiple options
-
Create a new Condition that inherits
StringOperatorCondition
.using Sitecore.Diagnostics; using Sitecore.Rules; using Sitecore.Rules.Conditions; using System; namespace Customer.Feature.FeatureName.Rules.Conditions { public class NewCondition<T> : StringOperatorCondition<T> where T : RuleContext { public string Value { get; set; } protected override bool Execute(T ruleContext) { Assert.ArgumentNotNull(ruleContext, "ruleContext"); // Logic that determines whether the rule applies. return true; } } }
-
Create a new Condition under
/sitecore/system/Settings/Rules/Definitions/Elements
-
Create a folder underneath the Condition to contain the option types.
-
Create items of Standard Template to represent each option type. Leverage the name within your logic and set the display name to something helpful for the author.
-
Set the Text of the condition to:
where the (context) has any [Value,TreeList,root=/sitecore/system/Settings/Rules/Definitions/Elements/Options&&selection={1930BBEB-7805-471A-A3BE-4858AC7CF696}, the list]
-
Set the Type of the condition to:
Customer.Feature.FeatureName.Rules.Conditions.NewCondition, Customer.Feature.FeatureName