3

假设用户本身能够添加新的分支模板。

在主页项目上,插入选项必须包含该分支模板文件夹内的项目。

在 sitecore 中,插入选项只能设置到特定项目。当我选择一个文件夹作为插入选项时,sitecore 会显示该文件夹项目(这是完全正常的)。

我需要做一些事情,比如在特定文件夹中动态显示项目,或者设置插入选项浏览对话框的起始路径。

这有可能吗?

4

2 回答 2

5

博文:https ://sitecorealekseyshevchenko.wordpress.com/2017/09/19/dynamic-insert-options/

创建“动态插入选项”模板,其中包含“ Droptree ”的唯一字段“起始路径”类型,源值为“ {3C1715FE-6A13-4FCF-845F-DE308BA9741D} ”-“ /sitecore/templates ”项的 ID。

然后将“动态插入选项”模板添加到模板的“基本模板”字段中的模板列表中,该模板应具有动态插入选项。

在此处输入图像描述

使用这样的配置修补“ uiGetMasters ”处理器:

<?xml version="1.0" encoding="utf-8" ?>
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <processors>
      <uiGetMasters>
        <processor mode="on"
                   type="DynamicInsertOption.Processors.GetDynamicInsertOption, DynamicInsertOption"
                   patch:before="processor[@type='Sitecore.Pipelines.GetMasters.CheckSecurity, Sitecore.Kernel']" />
      </uiGetMasters>
    </processors>
  </sitecore>
</configuration>

实现GetDynamicInsertOption处理器:

namespace DynamicInsertOption.Processors
{
    using Sitecore.Data.Items;
    using Sitecore.Diagnostics;
    using Sitecore.Pipelines.GetMasters;

    public class GetDynamicInsertOption
    {
        public void Process(GetMastersArgs args)
        {
            Assert.ArgumentNotNull(args, "args");

            var startingPath = args.Item["Starting Path"];

            if (!string.IsNullOrEmpty(startingPath))
            {
                for (int i = args.Masters.Count - 1; i > -1; i--) { args.Masters.RemoveAt(i); }

                var startingFolder = args.Item.Database.GetItem(startingPath);

                foreach (Item master in startingFolder.Children) { args.Masters.Add(master); }
            }
        }
    }
}

结果见下图:

在此处输入图像描述

于 2017-09-19T09:10:57.243 回答
0

您可以使用Sitecore Insert Options Rules而不是Sitecore Insert Options.

使用模板在该节点下查找/sitecore/system/Settings/Rules/Insert Options/Rules项目并创建新项目。Insert Options Rule现在编辑规则并将其设置为:

where the item is the Home item or one of its descendants
    and where the parent template is Folder
add YOUR_TEMPLATE insert option

您可以使用许多其他条件,如果您的要求需要,规则可能会更加复杂。

您可以在此处阅读更多信息:Sitecore 插入选项规则

于 2017-09-19T08:59:34.070 回答