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.

 

0 Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like
XOR in Python

XOR in Python

XOR Operator in Python is also known as “exclusive or”  that compares two binary numbers bitwise if two bits are…
How To

How to configure Git proxy?

If you are working in the corporate company all the internet requests usually goes through the corporate firewall.…