Creating Items from branch template in Sitecore Programmatically

Branch Templates are mainly used to build the reusable collection of items, or the hierarchy of items. Branch templates are very useful in creating the same structure at any path in Sitecore. In this article, let’s look at Creating Items from branch template in Sitecore Programmatically.

Creating Items from branch template in Sitecore Programmatically

If we are automating the content for Multi-site or Localizing the site then we can make use of branch template and feed the content to Sitecore.

For Eg: Let’s say we have created a Product branch template and we need to create products under Sitecore home node.

Below is the C# code to create items using the branch templates in Sitecore.

using(new Sitecore.SecurityModel.SecurityDisabler()) {
  string branchItem = "/sitecore/templates/Branches/Product";
  BranchItem branch = Sitecore.Context.Database.GetItem(branchItem);
  Assert.IsNotNull(branch, "Could not find Data branch at " + branchItem);
  Item homeItem = Sitecore.Context.Database.GetItem("/sitecore/content/home");
  homeItem.Add("product-1", branch);


This will add product-1 item under the home node and now we can fetch the product-1 item and edit the content accordingly.

Leave a Reply

Your email address will not be published.

Sign Up for Our Newsletters

Get notified of the best deals on our WordPress themes.

You May Also Like

How to Comment in PowerShell Script

Table of Contents Hide Single Line Comment in PowerShellMultiLine Comments in PowerShellSyntax for  Comment Based Help in FunctionsSyntax for Comment-Based Help in Scripts Like any other programming language, PowerShell also…
View Post