How to Create Branch Templates in Sitecore CMS

February 17, 2015

Blog | Development | How to Create Branch Templates in Sitecore CMS
How to Create Branch Templates in Sitecore CMS

This is the 20th post in our series about learning how to use and develop for Sitecore CMS, and the follow-up post to How to Configure Insert Options in Sitecore CMS”.

In this post, I cover how to create a branch template in Sitecore CMS. Branch templates can be used to build reusable collections of items, or even hierarchies of items. They are very useful when you want to implement similar structures in a number of places. This is particularly useful when building out new sites in a multi-site solution, or when creating content trees that have a consistent, repetitive structure.

Building the templates

This example will cover building a branch template for a multi-site solution. Before I jump into creating the branch template, it would be helpful to have a variety of templates to build with.

Create the following templates in /sitecore/templates/User Defined:

  • Home Page
  • Page
  • Website
  • Website Settings

For purposes of this example, no fields will be added to the templates, however icons have been set so that the types are easy to distinguish.

These templates will form our basic site structure. A website will contain a home page and settings item. The home page will contain an about page, contact page, and error page.

The tree will appear as:

  • Website
    • Home
      • About
      • Contact
      • Error
    • Settings

Building the Branch Template

Select the /sitecore/templates/Branches/User Defined folder in the content tree.

Create a “New Branch” using the button in the ribbon, the button in the folder, or the button in the context menu. A modal will appear where the root template item may be selected.

As the Website template is the root of the tree we’re creating, select User Defined/Website and click the “Create” button.

A new branch template item will have been created including a Website item named $name.

$name is a template token that will be replaced with the selected name when the branch template is used. Template tokens will be covered more at a later date.

Select the $name item, and create new items to build out the desired tree structure.

With the items in place, our branch template is complete and ready to be inserted.

Tim Leverett

Senior Developer
Tags
  • Content Management
  • Sitecore
  • Tutorial
Sitecore Survival Guide Volume 1

If you found this post helpful, there are plenty more where it came from! You'll find the first 10 here.

Download the first 10 posts in our Sitecore how-to series by Developer Tim Leverett!

Creating Content From a Branch Template

Select the /sitecore/Content item and select the "Insert from Template" option in the ribbon, folder, or item's context menu.

The standard "Insert from Template" modal will appear. Select /Templates/Branches/User Defined/Website.

Change the item name to Example and click the "Insert" button in the modal.

A new Website item will have been created with the given name, along with new subitems.


Check back for the next tutorial. And, as always, if you have any questions or if there's something you'd like to see covered, tweet us!

Recent Work

Check out what else we've been working on