Once a upon a time we were creating a website using Sitecore. We met in the conference room and started pretty peacefully. We were peaceful when were discussing how many page types we would need, we were still peaceful when we were talking what rendering we would have on each page type, and then… Someone mentioned the “B” word. I mean “branch” as in branch template. That was the moment when everything went … not so peaceful.
It seems that the question “should we create branch templates for the pages or keep data templates?” is a stumbling block for every development team. But should it be? Maybe the answer is simple, maybe not… let’s see:
We will start with some theory…
Everyone knows that each page is created based on the data template.
Data template is a structure where data types are defined. The data template is not used on its own. The standard values are used in the data template to provide initial values for items created out of it. It is possible to define the initial page layout and content in the standard values.
Every page created from a data template is heavily dependent on the template. The dependency is even bigger if the data template has the defined layout and content in standard values. Every change performed over the template will propagate to every page created from it. This happens because the page always keeps the reference to the data template it is created from. You can see it in the page quick info section.
Branch template is a solution that Sitecore has provided for creating item hierarchies in one click: either pages hierarchy or renderings hierarchy, located under the page item. The branch template is always built based on the data template, from which it inherits all of its fields and initial layout. It has no standard values, they become fields in the branch template. Upon creation of the item based on the branch template, the system COPIES the full hierarchy under the branch and creates a new list of items. The new items have no reference to the branch template they have been created from. The page quick information section displays the data template as the reference item for the pages created from the branch. That means that changes performed over a branch will never propagate to pages created from it, BUT changes performed over the data template would.
So, the purpose of the branch is to recreate hierarchies. We will review two types of hierarchies we can have in Sitecore:
- Pages Hierarchy (Case I)
- Renderings Hierarchy (Case II)
Pages Hierarchy (Case I)
Let’s imagine that your website theme is Traveling, and you are planning to create the hierarchy of the following kind:
City 1
- Attractions
- Restaurants
- Hotels
City 2
- Attractions
- Restaurants
- Hotels
City 3
- Attractions
- Restaurants
- Hotels
City 4
- Attractions
- Restaurants
- Hotels
Where every city page has the same hierarchy under it as well as each each page will have the similar layout or the set of renderings.
Obviously, every page will require a separate data template, but the Content Administrator will be doomed to recreate the same structure for every city having just the data templates.
However, if you use branches, the structure will be created in the branch, and as soon as you use the branch template to create a new city, it will be automatically created for you. After the pages have been created using the branch, they are no longer dependent on it and can be modified as much as you would like. The changes performed over the pages will not propagate back to the template, and changes performed over the branch will not change already-created pages.
As to the renderings hierarchy, this case is a little bit more complex and deserves to be described separately. To be continued…
Thanks for sharing!
Great article Jena!! Glad to see a new blogger on brainjocks.wpengine.com
Clear written and helpful. Thank you!
To branch or not to branch? Ultimately, that depends on what your team needs in order to find that sweet balance of collaboration and isolation.