How to add insert option Programmatically in C# Sitecore

214 Views Asked by At

Insert option is not coming, can anyone help on this how I can programmatically insert option with item when we do not have insert option in _standardValue of template

1

There are 1 best solutions below

0
mikaelnet On

When you create/edit the item from code, you can at the same time write to the Insert Options field, aka __Masters as field name, aka Branches as code constant, just as any other field. The field contains a pipe-separated list of template ID's. For example, like this:

item[Sitecore.FieldIDs.Branches] = "{TemplateId1}|{TemplateId2}|{...}";
// above is equivalent to item["__Masters"] = "...";

As you say, this will write a local value on the item being edited, and will therefore break any inheritance of the insert options that may be defined in __Standard Values. But in some scenarios this is actually better than having it on __Standard Values.