Everything in Sitecore is an item. The same is true for templates. A template in Sitecore is an item, which defines the structure and behavior of other items. Every item in Sitecore is an instance of some template. A template may also define the sections and fields into which it breaks down into and fulfills the content. Each section represents a sub-item under the template and every field is another sub-item under the item of the related section.
Templates are found in /sitecore/templates

Ukázka šablony, sekce s poli a umístění ve stromu

Ukázka šablony, sekce s poli a umístění ve stromu

Basic Types of Templates

Three basic types of templates can be defined in Content Editor/Template Editor.

Data Templates

The basic template type. It can contain fields and can be instanced by editors using insert page. This article discusses exactly this type of template.

Branch templates

The branch structure of templates. It allows you to define the entire branch of templates so by creating an instance of a branch template the whole item structure appears without the user having to create them one by one.

Command templates

It basically only deals with a command, which is evoked when creating an instance template. It is used for the automatic creation of items with business logic.

Standard template

Standard template

Inheritance

Templates can inherit from one or more other templates. Thanks to inheritance, we can define abstract templates commonly to more data templates. Thanks to this, content items can contain a number of fields without always having to re-define them separately for every template.

Standard template

Standard template is a basic template, which Sitecore provides for its function. This template does not contain any fields but it inherits from a number of other templates thanks to which we are able to define the display name, layout details, publishing restrictions and workflow, etc. on the items. All of the fields inherited into standard template begin with__.

The standard template is found in /sitecore/templates/System/Templates/Standard template

 __Standard Values

Apart from the fields, the template may also contain layout details defining preview, insert options defining hierarchal templates for creating initial values, including the use of tokens as for example, $name or for example, icons. However, not all these settings will transfer onto the item when creating an instance template. For this purpose, it is necessary to create a special type of item, _ Standard Values, under the template. It basically deals with an instance template, which defines the values of the fields, including fields from the Standard template, which are not defined on the instance template. They are common for all items created from the same template. Therefore, until the content item has its own defined value of some field, the value from the __Standard Values is used.

You can create __Standard Values using the Standard values button in the Ribbon on the Builder Options tab. In order for the Builder Options tab to appear, you have to choose a template from the branch in the left part of the window and switch over to the Builder tab in the content part of the window.

Identification and Navigation

You can easily click through to the template, from which the item is created, by means of the content item. It is also possible to change the template to another using the Change key on the Configure tab. Similarly, using the Links key in the ribbon on the Navigate tab, it is also possible to find out all the places, where the template is used. The Inheritance tab in the content part then shows us the branch structure, showing us everything that the template is made up of, including sub-inherited fields.

Unversioned vs. Shared

A field in a template can be defined as Unversioned or Shared. As is already clear from the title, the Unversioned field has the same value across all the versions within the language. The Shared field always has one valid value for all versions in all languages.

Fallback

The fields in the template can have a defined fallback. Fallback is a mechanism, which ensure the inserting the value of a field from another version or from another language, if it is empty. The fallback hierarchy of individual languages is defined in /sitecore/system/Languages.

It is necessary to define this detailed setting of fields on the individual item fields. Only the basic settings are available on the Builder tab on the template.

Recommendations when Creating Templates

Follow convention. Sitecore has prepared a document of recommended principles when designing and implementing Sitecore solutions, called Sitecore Helix. I recommend you read it. It will probably help you design all fields that you encounter in Sitecore. The section related to templates uses these classifications:

  • Interface template – contains fields, the convention is such that it begins with _, in C# it is an equivalent to interfaces.
  • Page type template – can have a layout, does not contain fields, inherits from one or more interface templates, instances are created from it, in C# it is equivalent to a class that implements one or more interfaces.
  • Datasource template – do not have layouts even though they are also inherited from the interface template, they are only used for referenced items as datasource for renderings.
  • Settings template – templates define the settings for the implementation of business logic, do not inherit from the interface template and are directly instanced.
  • Folder template – Do not use Common/Folder! Have your own folder template for every module. Thanks to this, you will be able to modularize the solution and use various insert options, authorizations, etc. on the file.

Do not use the Shared or Unversioned field unless it is absolutely necessary. It is always necessary to consider the language and cultural context carefully.