I have got a scenario that I put some conditions in EnableRule field in rendering variant field. If rule is true then it should render mapped field value and if false it should render some default value.

I tried below code

var personalization = Tracker.Current?.Interaction?.CurrentPage?.Personalization;

But looks like this code is for personalisation rule on renderings and does not work for EnableRule field.

Can anybody suggest how to check whether EnableRule field value is true or false?

1 Answer 1


So the rules on Rendering Variants tell Sitecore whether to use that variant field/item etc... or not use it. If the rule returns true, it will render it, if the rule returns false it will not.

Assuming you are using the older style item definitions and not scriban templates, you can't do what you are trying to do in a single variant item. But you could use 2 items to achieve it.

First create the Variant Field item that you want rendered if the rule is true, add the rule in and make sure that it returns true for a valid result.

Next, create a second variant item, maybe a Variant Text and add your default value in there. Add exactly the same rule as the field variant item, but this time, click on the where link in the rule. It will change to except where, resulting in the exact opposite of your field variant rule.

This will mean that only one of those items would be rendered based on your rule.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.