Sitecore 中规则和操作的 Hello World
Hello World for Rules and Actions in Sitecore
我正在学习 sitecore 规则并阅读 Rule Engine Cook Book 上的 material。我只想在项目保存时显示一条消息 window。这是我到目前为止所做的:
- 在
/sitecore/system/Settings/Rules/Item Saved/Rules
下添加了一个 Rule
。
规则 1:
其中项目模板是 Address entry
运行 Show Hello World
脚本
- 在
/sitecore/system/Settings/Rules/Item Saved/Actions/
下添加了脚本 Show Hello World
在脚本中有 3 个字段需要填写,如食谱所述,Enter a value in the Type field, or a value in the Code, References, and Language fields. Do not enter values in all four fields.
因此我用以下数据填写字段:
代码: Sitecore.Context.ClientPage.ClientResponse.Alert("More than one address not allowed under this item!");
参考文献:不知道写什么了
语言:CSharp
我不知道我做错了什么。任何帮助将不胜感激!
我认为我从未见过 code
字段用于 Actions
项目。
执行某些代码的最简单方法是使用 Type
字段,其值为:
My.Assembly.Namespace.MyCustomAction,My.Assembly
然后MyCustomAction
class代码:
using Sitecore.Data;
using Sitecore.Rules.Actions;
namespace My.Assembly.Namespace
{
public class MyCustomAction<T> : RuleAction<T> where T : ConditionalRenderingsRuleContext
{
public override void Apply(T ruleContext)
{
// your code here
}
}
}
我刚刚成功地重新创建了您的脚本并在新的 Sitecore 实例上对其进行了测试。以下是您必须遵循的步骤:
在 /sitecore/system/Settings/Rules/Definitions/Elements/Script
下添加模板类型 /sitecore/templates/System/Rules/Script
的新项目。我将我的项目命名为 "mydemoscript"。如果您是 运行 早期版本的 Sitecore(我认为是 7.2 或更早版本),那么您的保存路径将是 /sitecore/system/Settings/Rules/Item Saved/Actions
在脚本的 Code
字段中添加以下内容:<%Sitecore.Context.ClientPage.ClientResponse.Alert("More than one address not allowed under this item!");%>
在脚本的 Type
字段中添加 "CSharp"
保存您的脚本项目。
在/sitecore/system/Settings/Rules/Item Saved/Rules
下创建一条规则,我将我的规则命名为"mydemo"
在 Rule
字段中使用与之前相同的条件。对于动作使用 "run specific script" 动作。请务必编辑操作以引用您在步骤 1-4 中创建的脚本。
测试!
我正在学习 sitecore 规则并阅读 Rule Engine Cook Book 上的 material。我只想在项目保存时显示一条消息 window。这是我到目前为止所做的:
- 在
/sitecore/system/Settings/Rules/Item Saved/Rules
下添加了一个Rule
。
规则 1:
其中项目模板是 Address entry
运行 Show Hello World
脚本
- 在
/sitecore/system/Settings/Rules/Item Saved/Actions/
下添加了脚本
Show Hello World
在脚本中有 3 个字段需要填写,如食谱所述,Enter a value in the Type field, or a value in the Code, References, and Language fields. Do not enter values in all four fields.
因此我用以下数据填写字段:
代码: Sitecore.Context.ClientPage.ClientResponse.Alert("More than one address not allowed under this item!");
参考文献:不知道写什么了
语言:CSharp
我不知道我做错了什么。任何帮助将不胜感激!
我认为我从未见过 code
字段用于 Actions
项目。
执行某些代码的最简单方法是使用 Type
字段,其值为:
My.Assembly.Namespace.MyCustomAction,My.Assembly
然后MyCustomAction
class代码:
using Sitecore.Data;
using Sitecore.Rules.Actions;
namespace My.Assembly.Namespace
{
public class MyCustomAction<T> : RuleAction<T> where T : ConditionalRenderingsRuleContext
{
public override void Apply(T ruleContext)
{
// your code here
}
}
}
我刚刚成功地重新创建了您的脚本并在新的 Sitecore 实例上对其进行了测试。以下是您必须遵循的步骤:
在
/sitecore/system/Settings/Rules/Definitions/Elements/Script
下添加模板类型/sitecore/templates/System/Rules/Script
的新项目。我将我的项目命名为 "mydemoscript"。如果您是 运行 早期版本的 Sitecore(我认为是 7.2 或更早版本),那么您的保存路径将是/sitecore/system/Settings/Rules/Item Saved/Actions
在脚本的
Code
字段中添加以下内容:<%Sitecore.Context.ClientPage.ClientResponse.Alert("More than one address not allowed under this item!");%>在脚本的
Type
字段中添加 "CSharp"保存您的脚本项目。
在
/sitecore/system/Settings/Rules/Item Saved/Rules
下创建一条规则,我将我的规则命名为"mydemo"在
Rule
字段中使用与之前相同的条件。对于动作使用 "run specific script" 动作。请务必编辑操作以引用您在步骤 1-4 中创建的脚本。测试!