Sitecore Digital Marketing System, Part 1: Creating personalized, custom content for site visitors(自定义SiteCore中的 Item的Personalize的Condition) -摘自网络

Sitecore’s Digital Marketing System (DMS) can help you personalize the content your site displays to your users/visitors and can be easily customized to fit your specific requirements while using all the functionality that Sitecore already offers.

Let’s suppose you want to show different content modules to your users depending on their profile attributes like age, gender, number of twitter followers, number of achievements earned in the site, visitors without an account, etc.

We will need to let the site editor choose and create new rules that may include one or more profile attributes; therefore we can’t create a set of fixed rules to be used. Also, it is important to note that as result of our personalization, we will be required to:

-          Show a different sublayout

-          Hide the sublayout

-          Change the datasource of the sublayout

First, here is my User Profile class:

namespace RulesEngine.Session

{

public class UserProfile

{

public int UserId { get; set; }

public DateTime RegistrationDate { get; set; }

public string Nationality { get; set; }

public UserMaritalStatus MaritalStatus { get; set; }

public int NumberAchievements { get; set; }

}

public enum UserMaritalStatus

{

Single,

Married,

Divorced

}

}

To keep this demo as simple as possible, I’ll also create a dummy user session manager using a query string value to simulate the current logged in user:

namespace RulesEngine.Session

{

public static class UserSession

{

public static UserProfile GetCurrentUser()

{

var userId = HttpContext.Current.Request.QueryString["UserId"];

if (string.IsNullOrEmpty(userId))

{

//User not authenticated

return null;

}

UserProfile user = null;

switch (userId)

{

case "1":

user = new UserProfile()

{

UserId = 1,

RegistrationDate = new DateTime(2009, 10, 6),

MaritalStatus = UserMaritalStatus.Married,

NumberAchievements = 10,

Nationality = "British"

};

break;

case "2":

user = new UserProfile()

{

UserId = 2,

RegistrationDate = new DateTime(2005, 1, 26),

MaritalStatus = UserMaritalStatus.Single,

NumberAchievements = 55,

Nationality = "Amreican"

};

break;

case "3":

user = new UserProfile()

{

UserId = 3,

RegistrationDate = new DateTime(2011, 2, 14),

MaritalStatus = UserMaritalStatus.Divorced,

NumberAchievements = 3,

Nationality = "French"

};

break;

case "4":

user = new UserProfile()

{

UserId = 4,

RegistrationDate = new DateTime(1999, 8, 30),

MaritalStatus = UserMaritalStatus.Single,

NumberAchievements = 8,

Nationality = "Ecuadorian"

};

break;

}

return user;

}

}

}

Let’s start with the user’s nationality. All we need to do is create a new class with StringOperatorCondition as the base:

using Sitecore.Rules;

using Sitecore.Rules.Conditions;

namespace RulesEngine.Rules

{

public class NationalityCondition<T> : StringOperatorCondition<T> where T : RuleContext

{

//This is the value the editor will enter

public string Nationality { get; set; }

/// <summary>

/// This function will be called to test the condition

/// </summary>

protected override bool Execute(T ruleContext)

{

//Get the current user from our dummy user session manager

var user = UserSession.GetCurrentUser();

//Check if the user is logged in, otherwise return false

if (user == null)

return false;

//Use base function to compare the values

return this.Compare(user.Nationality, Nationality);

}

}

}

After a build of the solution, we need to register this new condition in Sitecore and copy the output dll to the website’s bin directory (if using a separate project). Open Sitecore’s content editor and navigate to the location: /sitecore/system/Settings/Rules/Conditional Renderings/Conditions and create a new folder:

Then we create a new condition:

The Text field is the content that will be shown to the editor when selecting this condition, we put the following text:

where the user‘s nationality [operatorid,StringOperator,,compares to] [Nationality,Text,,nationality name]

Notice that it has some special content surrounded by square brackets. This tag has four parameters: the first is the name of the a property in the condition, the second parameter is the name of the macro item (located in /Sitecore/System/Settings/Rules/Common/Macros), the third parameter is a parameter that will be sent to the macro item selected in the second parameter, and the fourth parameter is the text shown to the editor before he enters a value for the condition. In our case we have:


Parameter


Object


operatorid


Sitecore.Rules.Conditions.StringOperatorCondition.OperatorId


StringOperator


/sitecore/system/Settings/Rules/Common/String Operators


(empty)


We don’t need a parameter


compares to


This text will be shown to the editor


Parameter


Object


Nationality


Our RulesEngine.Rules.NationalityCondition.Nationality


Text


It will request a single line of text


(empty)


We don’t need a parameter


nationality name


This text will be shown to the editor

To apply this new rule to our site, we go to the item we want to personalize, then go to Presentation -> Layout Details:

Then on the new window, click on Edit:

Under Controls, select the sublayout and click on Personalize. Notice that this Personalize button only appears once you add DMS to your Sitecore installation:

Then click on New Condition:

Enter a name for the condition and then click Edit:

Now we can select our new condition:

See part two of this post for how to create conditions that will compare integer, dates and other custom values.

时间: 2024-08-30 13:37:36

Sitecore Digital Marketing System, Part 1: Creating personalized, custom content for site visitors(自定义SiteCore中的 Item的Personalize的Condition) -摘自网络的相关文章

【IOS笔记】Creating Custom Content View Controllers

Creating Custom Content View Controllers 自定义内容视图控制器 Custom content view controllers are the heart of your app. You use them to present your app’s unique content. All apps need at least one custom content view controller. Complex apps divide the workl

iOS Programming Recipe 6: Creating a custom UIView using a Nib

iOS Programming Recipe 6: Creating a custom UIView using a Nib JANUARY 7, 2013 BY MIKETT 12 COMMENTS Creating a custom UIView using a Nib Assumptions You are familiar with creating UIView subclasses, and instantiating UIView's both from a Nib file or

“System.BadImageFormatException”类型的未经处理的异常在 PurchaseDevices.Access.dll 中发生 其他信息: 未能加载文件或程序集“System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139”或它的某一个依赖项。试图加载格式不正确

引用sqlite的程序集时,有时会报如下异常: "System.BadImageFormatException"类型的未经处理的异常在 PurchaseDevices.Access.dll 中发生 其他信息: 未能加载文件或程序集"System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139"或它的某一个依赖项.试图加载格式不正确的程序. 解决方案:在配置

“System.IO.FileNotFoundException”类型的未经处理的异常在 mscorlib.dll 中发生

这个错误是我在打包的时候,发现的,因为我移动了我的工程的位置(从C盘移动到了D盘),看一下出错的代码: Dim strDB As String = System.Configuration.ConfigurationSettings.AppSettings("DBUser") '这里修改配置文件就可以确定是查询那个表了. '/// <summary> '/// depiction:<实例化一个DAL中的User表的类> '/// </summary>

System.Web.HttpRequestValidationException: 从客户端(dbFlag=&amp;quot;&amp;lt;soap:Envelope xmlns...&amp;quot;)中检测到有潜在危险的 Request.Form 值。

System.Web.HttpRequestValidationException: 从客户端(dbFlag="<soap:Envelope xmlns...")中检测到有潜在危险的 Request.Form 值. 在 System.Web.HttpRequest.ValidateString(String value, String collectionKey, RequestValidationSource requestCollection) 在 System.Web.Ht

System.Data.SqlClient.SqlException: 数据类型 text 和 varchar 在 equal to 运算符中不兼容。

一.引起的源头 环境:vs2015,sqlserver2008 相关程序包:ef6 定义了一个实体article public class Article { public string Data{get;set;} } EntityTypeConfiguration的配置 Property(a => a.Data).IsRequired().HasColumnType("text"); 这样可以正常生成表字段,而且类型也正确插入数据的时候,就引起了以下异常 System.Dat

GHOST CMS - 创建自定义主页 Creating a custom home page

创建自定义主页 Creating a custom home page 为你的网站创建一个自定义的主页是一个让你从人群中脱颖而出的好方法,并把你自己独特的印记存放在你的网上.本教程向您展示了如何在Ghost中自定义和开发自己的自定义主页. Creating a custom home page for your site is a great way to set yourself apart from the crowd and put your own unique stamp on you

随笔4:报错:“System.Windows.Markup.XamlParseException”类型的第一次机会异常在 PresentationFramework.dll 中发生 其他信息: “在“System.Windows.Baml2006.TypeConverterMarkupExtension”上提供值时引发了异常。”,行号为“11”,行位置为“18”。

问题描述: “System.Windows.Markup.XamlParseException”类型的第一次机会异常在 PresentationFramework.dll 中发生 其他信息: “在“System.Windows.Baml2006.TypeConverterMarkupExtension”上提供值时引发了异常.”,行号为“11”,行位置为“18”. 解决方案: 修改图片的“属性”页的“高级”中的“生成操作”,从“内容”改为“Resource”: (1)默认 (2)更改: 原文地址:

sitecore+score 在 Experience editor 添加新元素时associateed content 指向错误

Q:在sitecore的Experience editor页面添加component时,子元素的路径指向错误.如图: A: 首先你要整理思路,这个设置可能是在哪,是template还是control layout.当然这里肯定是跟页面control有关. 1.我们需要找到这个button的control layout.因为我们的项目是集成了score,所以根据score的手册我们知道这个button的路径在/sitecore/layout/Renderings/BootstrapUI/Conte