The branch concept in Sitecore is a method for creating multiple items at once. A branch consists of a branch item and below that item is several items. All of these items will be created when adding the branch item.
To do this in C# code is very simple:
using Sitecore.Data.Items; using Sitecore.Diagnostics; private const string _BRANCH_ITEM = "/sitecore/templates/Branches/MyBranches/MyBranch"; public void Create(Item parent, string name) { BranchItem branch = globalDataFolder.Database.GetItem(_BRANCH_ITEM); Assert.IsNotNull(branch, "Could not find Data branch at " + _BRANCH_ITEM); parent.Add(name, branch); }
The BranchItem class wraps the Sitecore item as a branch item. And the standard Add function on an item will take a branch item as parameter, creating the branch as subitems below the item.
As you can see there really is no difference from creating items based on branches compared to items created on templates, as the Add function takes both a TemplateItem and a BranchItem as parameter.
Pingback: Removing dead masters from Sitecore « Brian Pedersen’s Sitecore and .NET Blog
Pingback: Create and publish items in Sitecore « Brian Pedersen’s Sitecore and .NET Blog
Pingback: Sitecore 7 create item and update index at the same time | Brian Pedersen's Sitecore and .NET Blog
Pingback: Which of my old Sitecore posts are still valid in Sitecore 9? | Brian Pedersen's Sitecore and .NET Blog