Sitecore 7.X comes with many built-in rules for handy customization and personalization. For example, change the content for a user based on that users profile like “Where the visitors is from specific country”, but also a lot of common conditions like “when fieldname compares to specific value”.
If the condition that you want to use doesn’t exist, you can create it by yourself. Here is an example of custom condition inherited from StringOperatorCondition on checking user province then display different disclaimer.
Step 1: In Visual Studio project, create a class “ProvinceCondition”. Since the parameter “Province” passed in is item Id, we use a custom function to get actual province code.
Step 2: Under “/sitecore/system/Settings/Rules/Definitions/Elements/Conditional Renderings/”, create a new condition called “where the user province compares to specific province”, see below.
Text: where the user’s province [operatorid,StringOperator,,compares to] [Province,Tree,root=/sitecore/content/Global Assets/Regions,specific province]. Here the specific province is selected from a Sitecore item list “Regions”.
Type: The type field is populated with the [Namespace].[ClassName], [Compiled Assembly] of the corresponding custom code class we have built in step 1 above.
Step 3: Apply custom condition to personalize page content. Here I want to display Quebec disclaimer to users from Quebec and general disclaimer to users from rest of Canada. Select the control to personalize.
Make sure Conditional Renderings is selected into default tags.
Based on user province condition, choose between 2 different renderings. We can also choose to switch the data context (i.e. where the component gets its data from).