Sitecore Data Templates

"The Blueprint for Your Digital Masterpieces"

·

5 min read

Sitecore Data Templates

In general context we can define templates as something that is related to presentation which contains some view or partial view. Well, we can note that this is not the general case with Sitecore.

Any website or CMS works on the bases of data structures and that in Sitecore defines creating data templates which are to be followed with some standard parameters like assigning insert options, defining standard values, creating data items which consist of sections, fields, field type etc. In Sitecore, the templates are not related to any kind of presentation.

Templates are found inside : /Sitecore/Templates

How to use templates in Sitecore?

Templates in Sitecore are used to create Items even templates can also be referred to as an Item which consist of various fields and sections in Sitecore.
As we can see here that templates consist of 2 main Options:

  • Template Folder

  • New Template

Template folder generally consists of Templates and standard values associated with it. Template folders for example can be classified as base , components etc. as per our requirements we use Template Folders.

In Sitecore Templates we generally work with New Template as it gives us various methods that are used to create data Items, fields sections and so many features that are very useful to connect all the data.

How to insert data in a Template?

When we create a template it basically consists of 3 main things :

  • Template Builder : Template Builder is a special interface for creating templates in Sitecore where sections, and fields are created and edited in rows. Each row is made up of a field name, data type and source.

  • Inheritance : It contains information related to from where the templates have been inherited.

  • Content : This section consists of details that are to be given or that are used to be inherited from some base templates. Mainly, we inherit the item from base template and it is very useful as gives us the authority to remove redundancy of fields that are created and helps to improve reusability.

    *IF YOU SELECT NEW TEMPLATE THEN ONLY YOU WILL SEE THE OPTIONS IN BUILDER MENU AND ALSO WE CAN ASSIGN STANDARD VALUES USING THIS.***

What are Items, Sections and Fields in Sitecore Templates ?

Items, Fields and Sections :

  • What's an Item? Everything in Sitecore is an Item. Items are like building blocks for different things on a website, such as content, layouts, images, and more.

  • Fields on an Item: An Item has different types of fields. Fields are like slots where you can put different kinds of information. Examples of field types are "Title" for regular text, "Text" for fancy text, and "Banner Image" for pictures.

  • Types of Items: Items can represent many things like a web page, metadata, colors, user profiles, or product info. They can be simple with just a few details or complex with lots of information.

  • Identifying Items: In Sitecore, we can find Items by using their ID (like a unique code) or their path (like a location address).

  • Best Practice: It's usually better to use an Item's ID in code because it doesn't change, while the path might change if the Item is moved.

  • Sections: In Sitecore, Sections generally contains various fields and field types and they can be differentiated with the help of defining sections.

How to assign Standard Values for a template and what is the use of assigning them ?

What is the need of assigning standard values for a Template in Sitecore?

Assigning standard values for a template in Sitecore CMS is a powerful feature that helps ensure consistency and efficiency in content creation. Standard values are default values that are automatically assigned to new content items created from a specific template. This feature is particularly useful for fields that have common default values across multiple content items, such as a default author name, a default layout, or a default set of tags.

How to assign Standard Values for a Template?

For more information visit:

https://doc.sitecore.com/xp/en/developers/92/sitecore-experience-manager/standard-values-for-data-template-fields.html

Industry implemented hierarchy that we should follow while working with Sitecore:

Step 1:

While creating a template we need to also create another template that will inherit the current template using its standard values. Let me brief you by depicting in an image format:

  1. We created a template named as EventCard and assigned it with standard values.

  2. Now we need to create another TEMPLATE here we can see it named as EventCard Folder.

    (Note : We only named it as EventCard Folder but it is template only so do not mistake it as a template folder it is a TEMPLATE only.)

  3. Now, we need to assign EventCard to EventCard Folder using the Insert Options Dialog Box.

  4. This will assign EventCard to EventCard Folder and this EventCard Folder Template can we called inside the home of our project.

Why we need to follow this kind of Hierarchy ?

We need to follow this hierarchy because if we need to call the same components template again and again in our website then it really looks unstructured if we do not follow this hierarchy and also we can modify the copy of our template (here i.e EventCard Folder) as all the fields will be populated inside this template not at the main EventCard Template.

Basically, it is used to form a structured data entry in Sitecore where changes in the folder template does not affect the assigned templates values and it can be more user-readable.

How can we access the Templates inside the Content Editor section and where we need to assign all the values ?

Step 1:

When we create all the template and assign it to another template (here i.e inside EventCard Folder) we have to assign it inside another folder named as DATA folder which is located inside Templates Sections.

Location: sitecore/Templates/Projects/ProjectName/Data

Step 2:

Navigate to content folder and navigate inside the project that you created.

Step 3:

Now you can insert EventCard Folder inside this and after creating that you can insert EventCard Template as we have assigned it to that.

Where to insert values for each template?

We can insert values inside the standard values assigned for a particular template and the same values will be reflected while editing the content using content editor.

For more information refer:

https://doc.sitecore.com/xp/en/users/92/sitecore-experience-platform/content-authoring.html

https://sitecore.stackexchange.com/

Details on Content Editor and how it works reach out at:

https://devkheradiya.hashnode.dev/mastering-sitecore-content-unleashing-the-power-of-editors