Csharp/C#教程:Sitecore插入规则以确保最多(1)某种类型的儿童分享


Sitecore插入规则以确保最多(1)某种类型的儿童

在sitecore中是否有办法确保某种类型的项目只能拥有某种类型项目的1个孩子? 我正在阅读规则引擎食谱,但我没有得到太多细节。

我工作的其中一个网站要求在某个项目类型下面不能存在超过6个子项目。 我们考虑使用插入选项规则,但决定放弃这个想法,因为它不会阻止复制,移动或复制项目。

相反,我们决定使用专门用于此任务的处理程序扩展item:created事件。 下面是一个如何运作的精简示例。 一个明显的改进是从父项的字段中获取最大子限制(当然,仅对管理员可见)。 你甚至可以利用这里的规则引擎……

上述就是C#学习教程:Sitecore插入规则以确保最多(1)某种类型的儿童分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

 public void OnItemCreated(object sender, EventArgs args) { var createdArgs = Event.ExtractParameter(args, 0) as ItemCreatedEventArgs; Sitecore.Diagnostics.Assert.IsNotNull(createdArgs, "args"); if (createdArgs != null) { Sitecore.Diagnostics.Assert.IsNotNull(createdArgs.Item, "item"); if (createdArgs.Item != null) { var item = createdArgs.Item; // NOTE: you may want to do additional tests here to ensure that the item // descends from /sitecore/content/home if (item.Parent != null && item.Parent.TemplateName == "Your Template" && item.Parent.Children.Count() > 6) { // Delete the item, warn user SheerResponse.Alert( String.Format("Sorry, you cannot add more than 6 items to {0}.", item.Parent.Name), new string[0]); item.Delete(); } } } } 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1024420.html

(0)
上一篇 2022年1月7日
下一篇 2022年1月7日

精彩推荐