Whenever we discuss anything around Sitecore templates, we always mention about Data template and Rendering Parameter Template which is widely used & you can read about it here but we always forget to mention about Branch & Command Template which are indeed a powerful tool provided by Sitecore to achieve certain functionality.
Lets see Branch Template in this blog.
What is Branch Template?
We can say that Branch template is a solution that Sitecore has provided for creating item hierarchies in one click. A branch template consists of a template definition item, which can contain a item, a hierarchy of items, or multiple hierarchies of items. When a user creates an item based on a branch template, Sitecore duplicates the item(s) beneath the branch template definition item, including any field values, and then performs the token substitution on item names and field values based on Standard Values.
Where can we use this template?
There are couple of scenarios where the Branch template can come handy. One of which is, you have Press Release Details page and you have a carousel & few documents on it. You always create a Press Release item and then create 2 folders under it, one for Carousel & one for documents. This hierarchy can be created as a Branch Template. While creating Press Release item create through Branch template instead of Press Release data template and by default the hierarchy will be present for you.
Lets see an example on how to create a Branch Template.
- We need to create Press Release data template.
- We need to create 2 more data templates for Carousel & Documents folder, set the icons and insert options on it.
- In normal scenario, we will set both folder templates as the insert options on Press release template. Lets do this step as well.
- Now we will go to Branch template (/sitecore/templates/Branches/User Defined), I am creating the template for demo purpose hence creating under User Defined.
- Right click on User Defined >> New Branch
- Select Press Release data template under User Defined which we created earlier and click Create.
- A branch with name Press Release under $name as child item will get created.
- Right click on $name item and insert both the folders.
- We are done with creating the Branch template, lets create an item based on this template and check if we get the hierarchy we have defined.
- Go to the Home item (/sitecore/content/Home) >> Right click >> Insert from template.
- Select the Branch template for Press Release.
- Enter the name for the item and click Insert.
- The item with defined hierarchy gets created.
This is how we create the Branch Template. Hope this blog has cleared the concept of Branch Template and where we can use this template.
Thank you.. Keep Learning.. Keep Sitecoring.. 🙂
Pingback: Using Branch Presets to fix the static datasource path in the Branch Templates | Sitecore Diaries