Sitecore Fundamentals: Branch Template

What is a Branch Template?
In Sitecore Branch templates are a way to create content or item hierarchies automatically. With the help of branch templates the Content Editor can create an entire content sub-tree automatically with a single click when inserting a page/item in a Sitecore content tree. They can be thought of as a recipe a Content Editor can rely on to quickly build a frequently used content hierarchy which can save a lot of time especially if the hierarchy is complex.

A branch template contains an item that defines the branch template. This item branch template definition item is based on the /sitecore/templates/System/Branches/Branch template and it can contain zero or more item hierarchies. When a branch template is invoked, the items under the branch template definition item are duplicated at the point of insertion. Sitecore also performs token substitution ($name, $id, $date, $parentname, etc.) on item names and field values at the time of duplication.

Creating a Branch Template

Step 1: Select the /Sitecore/Template/Branches node. Right click and click on Insert and you should see an option create a “New Branch”, “Branch Folder”, “Command Template” or “Insert from template”. We’ll focus on the first two options. The “Branch Folder” option just creates Branch which can be used to keep things organized in a multi-site scenario. The New Branch option is what is used to actually create a branch template.

Step 2: Clicking on the New Branch option in Step 1 will open a dialog box to select the template you want to create a branch template for. After selecting the template click on the Create button.

You should now see a new node bearing the same name as the template you chose with another item under it of the chosen template type. In our our example we chose a Category Page Template so we have Category Page and an item of type Category Page with the $name token which will get replaced at the time of branch template use.

Step 3: Now, using branch template to insert a single item is of very little use. Lets add a couple of items under the $name node to create a simple hierarchy as shown in the figure. We created a folder called Local Assets and a component of type ContentBlock under the Local Assets folder. This hierarchy can be anything you like. Another thing to reemphasize is that you are not limited to a single hierarchy but you can have multiple hierarchies if the scenario needs it.

Using a Branch Template
Now comes the fun part. The content editor doesn’t need to do anything explicit to invoke the branch template aspect. They just need to insert the Category Page as usual but this time the content hierarchy gets created for them automatically.

The newly created hierarchy based on the branch template looks like this: