Data definition and template overview

When you set up a website, the first step is to create the data structure. In Sitecore, creating the data structure means creating data templates, defining standard values, assigning insert options, and creating content items. And, doing this, revolves around one fundamental concept In Sitecore - the template. A template has nothing to do with the presentation of content. Instead, it determines the structure of the content. A template is an item that defines both the structure and behavior of other items. There are different types of templates in Sitecore including:

  • Data templates, which define fields used to control how data is entered. They determine the exact field sections, field types, and field names that make up each item. In other words, data templates form the framework around which items are built.

    Sitecore associates a data template with every item in the content tree. It is the field types that determine the editing controls shown to the user and they contain the raw values that are stored in the database.

  • Branch templates, which enable you to create a set of items rather than a single item. A branch template consists of a branch template definition item, which can contain a single item, a hierarchy of items, or multiple hierarchies of items. With branch templates, Sitecore duplicates the items beneath the branch template definition item, including field values, and then resolves tokens in item names and field values.

  • Command templates, which allow you to insert items using logic rather than a predefined structure.

Another important concept in Sitecore is template inheritance. Templates inherit from one or more base templates. A data template, for example, inherits sections and fields from its base templates. When a data template inherits from other templates, all fields are merged. You can an example of a template hierarchy in Template Inheritance example.

All data templates inherit from the standard template. The standard template does not contain any fields, but it inherits from a number of other templates. All fields that were inherited into the standard template begin with an underscore, for example __Ribbon or __Tracking.

Important

You must create all templates in the Master database, not the Core database.

When you are working with templates, keep in mind the following best practices:

  • Organize data templates by site. In the content tree (sitecore/Templates), create a folder for each site and add your templates.

  • Use easily understood data template names so that when content authors insert a new item and see the name of the data template, they understand what the template is for. Similarly, give meaningful names to field sections that group similar fields together.

  • Use unique names for fields and field sections because these are merged from the inherited base templates.

  • Assign icons to data templates that content authors see so that they can easily identify what type of data template an item was created from. Similarly, assign icons to field sections.

  • Use template inheritance to reduce duplication. Fields that are shared between several data templates can be grouped into base templates and inherited. For example, all pages will have a Page Title (to be displayed in the browser’s title bar) and a Meta Description. These sorts of fields can be grouped together as Page Meta Data. Similarly, most pages will have summary information and main content.

  • Avoid redundant fields (for example, fields that are inherited but never used by the data template).

  • Define specific field names (such as Page Summary Heading instead of simply Heading). All helpers and controls that render field content eventually pass through the FieldRenderer pipeline, which requires the field’s name rather than its ID.

  • Define field names based on content type and not location because content is often reused and does not necessarily appear only in one location.

  • When a field needs to be translated and you need to track each version, make the field a versioned field. When a field needs to be translated but there is no need to track each version, make the field an unversioned field.

  • Use field tokens (such as $name, $id, $time) when several fields use similar content. Tokens are defined on the data template standard values, and must be done for every language if the field in question is versioned or unversioned. Tokens are replaced the moment an item is created.

  • Set field defaults on standard values. Using standard values, you can ensure that default data is automatically inserted into newly created items. Standard values are default values that populate null fields of existing items or fill data into newly created items.

Do you have some feedback for us?

If you have suggestions for improving this article,