Sitecore – custom rules for DMS

Sitecore DMS allows business users to personalise content based on a set of predefined rules. This post describes the process of creating custom rules that can be used in Sitecore Page Editor.

Relevant to Sitecore 7.0 – 7.2

There are a few steps that need to be taken.

1. Create the rule in Visual Studio

namespace SCCoral.Business
{
  public class UrlContains : StringOperatorCondition where T : RuleContext
  {
 
  public string Value
  {
   get;
   set;
  }
 
  protected override bool Execute(T ruleContext)
  {
   var uri = Sitecore.Context.Item.Uri.ToString();
   var condition = this.Compare(uri, this.Value);
   return condition;
  }
 }
}

Notes:

  • The class must inherit the abstract class RuleContext
  • The class should inherit an operator class. ie StringOperatorCondition, IntegerComparisonCondition

2.Create the rule in Sitecore

Create a new element folder here: /sitecore/system/Settings/Rules/Definitions/Elements/. This is the rule group. Inside the folder create the rule. For best results DUPLICATE an existing element folder:

Sitecore Rule - Content Editor 1

3.Create the rule tag

Create a tag for the rule folder (the name must be the same) here /sitecore/system/Settings/Rules/Definitions/Tags

Sitecore Rule - Content Editor 2

4. Assign the tag to the rule added in step 2

Sitecore Rule - Content Editor 3

5. Set the tag (custom rules and group) to be used

Locate the element here: sitecore/system/Settings/Rules/Conditional Renderings/Tags/Default

In the multi-list view add the newly created tag

Sitecore Rule - Content Editor 4

6. Test the new rule using the Page Editor

Open the Sitecore Page Editor, click a component and select “Create/edit the personalization options for this component”. Then pick the new rule.

Sitecore Rule - Content Editor 5

Done – creating a new rule is all too easy if you know how!!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>