Create an insert rule
How to create an insert rule to restrict what users can insert under existing items.
You can assign insert rules to an insert option to dynamically redefine the effective insert options that are available for a user at runtime.
To create an insert rule:
Create a class that inherits from the
Sitecore.Data.Masters.InsertRule
class with a constructor that accepts a singleSystem.Int32
parameter, and override theExpand()
method. You can use the following code sample:namespace Namespace.Data.InsertRules { public class ClassName : Sitecore.Data.Masters.InsertRule { public ClassName(System.Int32 count) { } public override void Expand( System.Collections.Generic.List<Sitecore.Data.Items.Item> insertOptions, Sitecore.Data.Items.Item item) { //TODO: manipulate insertOptions } } }
In the Content Editor, insert any required project-specific folders under
/Sitecore/System/Settings/Insert Rules
using the/Templates/Common/Folder data template
template.In the relevant project-specific folder, insert an insert rule definition item using the
/System/Branches/Insert Rule data template
template.In the insert rule definition item, in the Data section, in the Type field, enter the signature of the class.
Note
To assign the insert rule to other items, see Assign or copy insert options.