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.
Sitecore Digital Marketing System, Part 1: Creating personalized, custom content for site visitors(自定义SiteCore中的 Item的Personalize的Condition) -摘自网络的更多相关文章
- View Controller Programming Guide for iOS---(四)---Creating Custom Content View Controllers
Creating Custom Content View Controllers 创建自定义内容视图控制器 Custom content view controllers are the heart ...
- 【IOS笔记】Creating Custom Content View Controllers
Creating Custom Content View Controllers 自定义内容视图控制器 Custom content view controllers are the heart of ...
- “System.BadImageFormatException”类型的未经处理的异常在 PurchaseDevices.Access.dll 中发生 其他信息: 未能加载文件或程序集“System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139”或它的某一个依赖项。试图加载格式不正确
引用sqlite的程序集时,有时会报如下异常: "System.BadImageFormatException"类型的未经处理的异常在 PurchaseDevices.Acces ...
- System.Data.SqlClient.SqlException: 数据类型 text 和 varchar 在 equal to 运算符中不兼容。
一.引起的源头 环境:vs2015,sqlserver2008 相关程序包:ef6 定义了一个实体article public class Article { public string Data{g ...
- sitecore系统教程之使用修补程序文件自定义Sitecore配置
您可以使用修补程序文件在Sitecore中添加或更改配置设置.Sitecore将修补程序文件与Sitecore.config 文件合并,以创建在运行时使用的配置文件. 本主题描述: 补丁文件放置 补丁 ...
- [转载]未能从程序集“System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”中加载类型“System.Web.WebPages.DisplayModeProvider”
转载于http://bkcoding.cn/post_1210.html 使用vs2010开发asp.net mvc程序时,出现 未能从程序集“System.Web.WebPages, Version ...
- [转]Creating a custom ribbon for Outlook 2013, 2010 and toolbar for Outlook 2007, 2003 – C# sample
本文转自:https://www.add-in-express.com/creating-addins-blog/2013/05/21/outlook-ui-customization-ribbons ...
- P/Invoke出现错误 System.NullReferenceException”类型的未经处理的异常在 未知模块。 中发生 未将对象引用设置到对象的实例。
问题 “System.NullReferenceException”类型的未经处理的异常在 未知模块. 中发生 未将对象引用设置到对象的实例. 解决方案 1.尝试 用管理员身份运行CMD,输入nets ...
- Creating a custom analyzer in ElasticSearch Nest client
Creating a custom analyzer in ElasticSearch Nest client Question: Im very very new to elasticsearch ...
随机推荐
- 解决ubuntu中vi不能正常使用方向键与退格键的问题
方案一: 问题: ubuntu中vi在编辑状态下方向键不能用,还有回格键不能删除等我们平时习惯的一些键都不能使用. 解决办法: 可以安装vim full版本,在full版本下键盘正常,安装好后同样使用 ...
- TCP协议可靠性数据传输实现原理分析
http://blog.csdn.net/chexlong/article/details/6123087 TCP 协议是一种面向连接的,为不同主机进程间提供可靠数据传输的协议.TCP 协议假定其所使 ...
- Armitage主屏幕说明与命令行启动
(1)我们将Armitage主屏幕标注为A.B和C A:该区域显示预配置的模块.您可以在模块列表下面的文本框中输入要查找的模块进行查找. B:该区域显示我们可以进行漏洞测试的活跃主机. C:该区域显示 ...
- 对于eclipse新建maven工程需要注意的地方。
新建项目的时候,如果想配置默认的maven的jre为1.6或者别的. http://hi.baidu.com/hi_hi/item/765ec8bbc49880d384dd79d1 1.cmd命令建立 ...
- Android2.3.7源码结构分析
对Andorid系统进行分析或者系统功能定制的时候,我们经常需要在众多文件中花费大量时间定位所需关注的部分.为了减轻这部分枯燥而不可避免的工作,本文对2.3.7版本的源码结构进行了简单分析.希望对刚加 ...
- Mysql DBA 20天速成教程,DBA大纲
Mysql DBA 20天速成教程 基本知识1.mysql的编译安装2.mysql 第3方存储引擎安装配置方法3.mysql 主流存储引擎(MyISAM/innodb/MEMORY)的特点4.字符串编 ...
- poj 2195 Going Home(最小费用最大流)
题目:http://poj.org/problem?id=2195 有若干个人和若干个房子在一个给定网格中,每人走一个都要一定花费,每个房子只能容纳一人,现要求让所有人进入房子,且总花费最小. 构造一 ...
- poj 2506 Tiling(递推 大数)
题目:http://poj.org/problem?id=2506 题解:f[n]=f[n-2]*2+f[n-1],主要是大数的相加; 以前做过了的 #include<stdio.h> # ...
- 结构体buf_chunk_t
/** Buffer pool chunk comprising buf_block_t */ typedef struct buf_chunk_struct buf_chunk_t; /** A c ...
- SPOJ-OPTM Optimal Marks ★★(按位建图 && 最小割)
[题意]给出一个无向图,每个点有一个标号mark[i],不同点可能有相同的标号.对于一条边(u, v),它的权值定义为mark[u] xor mark[v].现在一些点的标号已定,请决定剩下点的标号, ...