Add a custom personalization rule for conditional rendering
Sitecore includes several default personalization rules that you can use for conditional rendering. If you have specific needs that aren't addressed by the existing rules, you can create your own personalization rules. This topic explains how to create a custom personalization rule that you can use for conditional rendering on the Default device.
Add a custom rule
-
In
sitecore/system/Settings/Rules/Definitions/Tags
, right-click Tags and ,click Insert > Tag, then enter a name for the new tag. -
In
/sitecore/system/Settings/Rules/Definitions/Elements
, right-click Elements and click Insert > Element Folder to create a rule element folder. -
Right-click the newly created element folder and click Insert > Condition, then enter a descriptive name for the new condition.
-
In the new condition's Text field, enter a combination of user-facing text for the person who uses the rule, and the input fields that create the rule conditions, for example: "Where the query string parameter compares to value", where the underlined text represents the conditions. Define each condition in a pair of square brackets that contain four comma-separated values:
-
The name of the property in the .NET class that implements the condition. When the user enters a value for the condition, it's assigned to the .NET class property.
-
The name of the macro that contains predefined functionality. For example, a user interface that allows the user to select an integer. If you leave this empty, the default interface is used. You can use existing macros, for example, using the string operator:
RequestResponsewhere the current contact's [AreaName,,,Area Name] [Key,,,Key] [OperatorId,StringOperator,,compares to] [RuleString,,,specific value]
NoteYou define the macro in
/sitecore/system/Settings/Rules/Definitions/Macros
. -
URL parameters related to the user interface, that you specify if you're using a macro to create an interface. For example, to specify the
/sitecore/Content/Home
item as the root for a selection tree, enterroot=/sitecore/Content/Home
. You can leave this empty if no URL parameters are expected. -
The text to display in the Rule Set Editor. When the user selects the value, the text changes accordingly.
-
-
In the new condition's Type field, enter the fully qualified name of the .NET class that implements the condition, in the following format:
namespace, assembly name
. -
In the new element folder, click Tags > Default, and assign the tag you created in step 1.
-
For the rule to appear in the Rule Set Editor under Conditional Renderings, open
/sitecore/system/Settings/Rules/Conditional Renderings/Tags/Default
and assign the new tag to the Conditional Renderings tag. -
Finally, in the Sitecore bin folder, add the DLL containing the .NET class that implements the condition. Ensure that the namespace and class name match the value specified in the Type field above. The .NET class needs to inherit from one of the following classes:
-
To implement Boolean conditions, use
Sitecore.Rules.Conditions.WhenCondition
. -
To compare string values, use
Sitecore.Rules.Conditions.StringOperatorCondition
. -
To compare values of other types, use
Sitecore.Rules.Conditions.OperatorCondition
.
-
After you complete the process, the rule is available in the Sitecore Rule Set Editor.
For example, the following text:

Results in the following condition:
