I have a page which is having many controller rendering but I want to execute only some of them based on any condition. Is it possible to do it in sitecore programmatically?
-
2You can apply personalization rule to hide that rendering or you can pass some rendering parameter so on the basis of that parameter you can show/hide the component– Swati GuptaJan 3, 2020 at 5:47
-
Actually i am calling web api and from there i am checking the condition if it is true then only i have to show otherwise i have to hide.– Durgesh GuptaJan 3, 2020 at 6:27
-
How about having a common condition in code which will be triggered for all such controller renderings. Please provide some more detail to attract better solutions.– sukeshJan 3, 2020 at 9:43
1 Answer
To do the same follow below steps:
- First you need to create custom personalization rule.
- Write you custom code which will inherit RuleContext Class, for check the condition where you will match value one which comes from web API and other you set in your rule.
- If both the value will be matched then show or hide your rendering bases on the condition.
For more details how to create custom Personalization rule, You can find more details here: Custom Personalization Rules in Sitecore