Sitecore 7.x Personalization – Part 2: Create Custom Condition

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.

Sitecore8

 

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.

Sitecore10

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.

Sitecore12

Make sure Conditional Renderings is selected into default tags.

Sitecore15

 

 

Sitecore13

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).

 

Sitecore14

This entry was posted in Context Intelligence, Information Technology, Sitecore and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s