Sitecore - how to show templates under specific folder, inside insert options context menu

967 Views Asked by At

Lets say the user itself is able to add new branch templates.

And on a homepage item, insert options must consist of items inside that branch templates folder.

In sitecore, insert options can only be set to specific items. When I select a folder as an insert option, sitecore shows that folder item (which is perfectly normal).

I need to make something like either showing items dynamically inside a specific folder, or setting the starting path of insert options browsing dialog.

Is any of this possible ?

2

There are 2 best solutions below

2
On BEST ANSWER

Blog post: https://sitecorealekseyshevchenko.wordpress.com/2017/09/19/dynamic-insert-options/

Create 'Dynamic Insert Option' template wich contains the only field 'Starting Path' type of 'Droptree' and source value is '{3C1715FE-6A13-4FCF-845F-DE308BA9741D}' - id of '/sitecore/templates' item.

Then add 'Dynamic Insert Option' template to list of templates in 'Base template' field of the template which should have dynamic insert options.

enter image description here

Patch 'uiGetMasters' processor with such config:

<?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>

Implement GetDynamicInsertOption processor:

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); }
            }
        }
    }
}

The result see on pic below:

enter image description here

6
On

You can use Sitecore Insert Options Rules instead of Sitecore Insert Options.

Find /sitecore/system/Settings/Rules/Insert Options/Rules item and create new item under that node using Insert Options Rule template. Now edit the rule and set it to:

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

There are plenty of other conditions you can use and the rule can be much more complex if you requirements demands it.

You can read more here: Sitecore Insert Options Rules