In Sitecore before creating any item we need to define the template. We can relate the template with the table schema in RDBMS. Just like the table is created using a single or set of columns of specific data types, Sitecore templates are created using fields of standard or custom data types defined in Sitecore.
Sitecore templates are defined under the following path under the content tree: /sitecore/templates
We can create Sitecore items using different types of templates. Sitecore templates can be broadly categorized into the below types:
Data templates
Branch Templates
Command Templates
Data Templates:
Data template or data definition template items are used to define the type of content item. If we expand the Sitecore content tree, each item is created by using some sort of data template. The data template contains sections and sections contain Sitecore fields created using predefined or custom field types.
Sitecore Template example
In the above example, we can see that Report is a custom data template created consisting set of fields capsulated inside different sections. Each field is set up using a specific field type.
The Source field is majorly used to set up the root node of the data source for that particular field. We can also use the Sitecore query to define the relative data source.
The Shared check box defines that the value assigned to the field will be shared across all the numbered as well as language versions.
The Unversioned check box defines that the value assigned to the field will be shared only among the numbered version of that language version of an item but not across the other language versions.
Templates can be also inherited by setting the Base template multi-list field of any template:
Base template
By default, all the templates are created using System Template: /sitecore/templates/System/Templates/Template and inherit the Standard template.
Template Inheritance
Template inheritance is a crucial step to avoiding the redundancy of fields and improving reusability. So defining the templates and their inheritance sets the foundation of the Sitecore environment.
Standard Values item is created under the main template item and it is mainly used to set up default values for template fields. By default standard values item will not be present under the template item, but can be created using the below option:
Option to create Standard template
Standard values can also be used to set up dynamic field values using predefined Sitecore tokens.
The default page layout(presentation detail)
Insert options
Default workflow
Data templates can be further categorized into below types:
Base Templates: We can relate the Base templates with the parent/base class in OOP’s inheritance concept. They will possess fields that will be reused in the other templates inherited by the base template. Basically while setting up the base template fields we need to make sure that they are going to be commonly used in multiple derived templates to avoid redundancy.
Page Templates: Along with the fields with the page template we will also have a default layout defined using presentation details. This consist of setting up the main layout and the components which will be added by default when an item is created using the page template.
Folder Templates: Folder templates are mainly used to organize other items inside the Sitecore content tree.
Rendering Parameter Templates: Rendering Parameter templates are kind of metadata templates. They are not used to store the content information. They are paired with Renderings to define some configuration/setting information related to rendering. They are created using following template: /sitecore/templates/System/Layout/Rendering Parameters/Standard Rendering Parameters. They need to be configured in the rendering parameter template field of a rendering item.
Data source Templates: Data source templates as their name suggest it mainly used to store content information. They are almost the same as that Page templates but without presentation details.
Branch Templates:
A branch template is created using the hierarchy of data templates and command templates. The main purpose of using a branch template is to instantly create the item hierarchy in the Sitecore content tree.
When we select a branch template from the insert options, Sitecore duplicates the items beneath the branch template definition item, including field values, and then performs token updates on item names and field values.
Sitecore branch templates are stored under the following item path: /sitecore/templates/Branches
Branch Template inside Sitecore Content Tree
Command Templates:
Command template is mainly used to perform some operation before the item is inserted or created in the Sitecore content tree.
Command templates are created using /sitecore/templates/System/Branches/Command Template.
Command templates need a class and the method which will execute when they are triggered. For e.g. via insert options.
Command template class should implement Sitecore.Shell.Framework.Commands.Command class and should override its execute method -> public override void Execute(Sitecore.Shell.Framework.Commands.CommandContext context)
Once the template class is defined and the logic is written for executing the method, we need to add the command template in /App_Config/Commands.config file under Configuration -> Command element
Commands.config
In a custom command, the config element name defines the command code of the command the type defines the assembly class and the method. In the command template definition item, in the Data section, for the Command field, we will have to enter the command code.
Example: Command Template Definition Item
Comments