Branch templates
Branch templates (also known as a branch template definition items) enable users to create multiple items using a reusable, predefined structure. The branch template consists of a branch template definition item, including all of its descendants, and can contain values for any fields in the items. When a user chooses a branch template from the insert options, Sitecore duplicates the items beneath the branch template definition item, including field values, and then performs token substitution on item names and field values. You can assign branch templates along with data templates and command templates.
You do not need to create a branch template for every data template. Use branch templates when you want to:
-
Copy initial field values into a created item (rather than inheriting them from the standard values). This includes both field values for the Standard template fields (which are assigned using the ribbon controls, for example, the item’s icon or access right assignments) and fields defined in custom data templates (such as a product number).
-
Insert multiple items.
-
Assign access rights to inserted items.
-
Control which accounts can insert items using the branch template.
-
Provide content authors with the ability to create multiple items at once (either siblings or descendants). Multiple content subtrees can be created using branch templates.
You can create any number of items within a branch template definition item, and each item can have any number of descendant items. When a user creates an item using the branch template, Sitecore replicates all descendants of the branch template definition item before expanding tokens.
You can insert a new branch template definition item using the Branch data template (/System/Branches/Branch data template
) or the New Branch command template (/Branches/System/Branch/New Branch command template
). If you use the command template, Sitecore creates a branch template definition item named after the data template you specify, and creates an item named $name
, based on that data template within the branch template definition item.
You can enter values including the following tokens in the fields of each item within the branch template definition item. Sitecore expands these tokens in field values in each of the items inserted using the branch template.
-
$name
- the name entered by the user when inserting the item. -
$id
- the ID of the item. -
$parentid
- the ID of the parent of the item. -
$parentname
- the name of the parent of the item. -
$date
- the system date (yyyyMMdd). -
$time
- the system time (HHmmss). -
$now
- the date and time (yyyyMMddTHHmmss).
Unlike standard values, which Sitecore stores in a single standard values item for each data template and applies to all items based on that template that do not have values for those fields, Sitecore duplicates field values within branch template definition items to each item created using that branch template. To avoid data duplication, use standard values instead of field values in branch templates.
Actions carried out when using a branch template
When a user invokes the branch template, Sitecore:
-
Copies the descendants of the branch template definition item, including all field values, to create new items.
-
Performs token substitution on the new items, replacing
$name
and other tokens in both item names and field values with the name entered by the user when invoking the branch template.
In branch templates consisting of one child item with zero or more descendants, the name of that child is typically $name
so the user can specify the name of the root item to create. For item names in branch templates, only $name
is supported
For any field not overriding its standard value in the branch template, the corresponding field in the new items contains its standard value, unless the standard value contains a token such as $name
, which Sitecore also replaces with the given item name.
Field values in branch templates could easily result in data duplication. Therefore, template standard values are generally preferable to field values in branch templates. You must also remember that field values in branch templates are not inherited like template standard values, but are copied.
Therefore, changes made to a branch after creating items using that branch are not reflected in the items previously created.