Sitecore Rules Engine: How to create a custom condition

In this How to I will build a custom condition for the Sitecore Rules Enginge. This How To is a proof of concepts based on a webinar (in Dutch)  about the Rules Engine. I presented this webinar earlier this year and you can watch the webinar on Youtube by clicking this link.

Before we start writing code I’ll explain the business case we are trying to resolve.

The ‘case’:
The business user want to personalize the website based on the website the visitor comes from (the http referrer).  For now he is only interested in Facebook and Twitter.
If the visitor visits our site from Facebook the Facebook Like button of our own Facebook page must be visible on the homepage.
If the visitor visits our site from Twitter our Twitter Tweet stream must be visible on the homepage.

Oke, Now start building it!

Create templates

Create a template called Sidebar Text, this template has two field; a Sidebar Title (Single-Line Text field) and a Sidebar Text (Rich Text field).

Create a template called Standaard Text, this template one field called Text (Multi-line Text).

Set up the content tree

Create a folder called Sidebars  and add two Sidebar Text items with the following values:

Create a folder called Http Referrers and add the following items:

  • Item name: Twitter
    • Text: twitter.com
  • Item name: Facebook
    • Text: facebook.com

Create presentation component

Create the Sidebar Text rendering for displaying the Sidebar Title and Sidebar Text.

Open development center and click Create a New XSLT rendering and name the rendering Sidebar Text. Add the following code to the rendering template:
Continue reading “Sitecore Rules Engine: How to create a custom condition”