---
title: "Add a custom personalization rule for conditional rendering"
slug: "add-a-custom-personalization-rule-for-conditional-rendering"
abstract: "Describes how to create a custom personalization rule for conditional rendering. The new rule can be used in the Rule Set Editor for personalization."
---
# 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

1. In `sitecore/system/Settings/Rules/Definitions/Tags`, right-click **Tags** and ,click **Insert** > **Tag**, then enter a name for the new tag.
2. In `/sitecore/system/Settings/Rules/Definitions/Elements`, right-click **Elements** and click **Insert** > **Element Folder** to create a rule element folder.
3. Right-click the newly created element folder and click **Insert** > **Condition**, then enter a descriptive name for the new condition.
4. 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:

        ```text
        where the current contact's [AreaName,,,Area Name] [Key,,,Key] [OperatorId,StringOperator,,compares to] [RuleString,,,specific value]
        ```

        > [!note]
        > You 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, enter `root=/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.
5. 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`.

    ![A screenshot of the Content Editor Type field for a new condition.](https://doc.sitecore.com/api/markdown-image/xp/en/users/100/sitecore-experience-platform/images/CustomPersRuleType_08-23.png)

6. In the new element folder, click **Tags** > **Default**, and assign the tag you created in step 1.
7. 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.
8. 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:

![A screenshot of text input for a condition.](https://doc.sitecore.com/api/markdown-image/xp/en/users/100/sitecore-experience-platform/images/CustomPersRuleText_08-23.png)

Results in the following condition:

![A screenshot of the Sitecore Rule Set Editor.](https://doc.sitecore.com/api/markdown-image/xp/en/users/100/sitecore-experience-platform/images/CustomPersRuleSetEditor08-23.png)