In this tutorial, you will learn about Sitecore templates and how you can create them. Templates are the basic building block of any Sitecore website. If you are new to Sitecore and you want to start building objects, this is the tutorial for you 🔥🔥🔥
What Is A Template?
In every other CMS system that I have worked with, a template is usually a layout that defines how a web page will look. In Sitecore, this isn't' the case. I found it easier to refer to templates as data templates. A Sitecore template defines an entity within Sitecore. Within the data template, you define properties. Based on what properties you expose in the template, a content editor can use that template to add data into the CMS. A template has nothing to do with how something looks. You could compare it to a class in C#. A template simple defines the behaviour of a Sitecore object 🤔
If you want to find a list of the templates in your project, open up your Sitecore content editor and navigate to the templates section. You can find this here:
Sitecore
âž¡ Templates
The template area should look like this:
Here you will find a list of default Sitecore system templates. On a usual project, it is usually good practice to create your custom templates within a different folder. I recommend that you create a new folder called Sites
:
Another popular naming convention is User Defined
:
My preference is Sites
so we will use that. In your Sites
folder, I recommend creating another folder that is named after your website. I have found that the more you split your folder structure up, the greater control you will have. When it comes to things like object mappers and editor permissions, the more granular you can be in your folder structure, the more control you have over what you can target. If you run two websites in your Sitecore instance and want to share templates between them, most teams I have encountered define templates in a separate folder called Common
:
To create a new template, in your new website
folder, right-click on it and from the context menu select New Template
:
Here you will be presented with the New Template
screen. A useful thing to understand is the ability to create base templates. Base templates are really useful when you have shared groups of properties between your templates. For example, you could create a base template that contained all the fields required to render a web pages meta-data section. This technique can save a lot of duplication when you start building your website in anger! By default, all templates will inherit from the default Sitecore base template. Any new templates that you create will default to inheriting from this item:
To create a template give it a name and set the base template type. Next, you need to decide where in the content tree your template should live. As mentioned above, I prefer to organise my templates in specific folders, so I would put my template within its own folder, rather than putting all of them in one giant folder:
After you create your template, you can start to add properties to it. You can now add sections and fields using the Builder
tab. You can build a template using two types of components:
Sections
are used to group similar fields togetherFields
are used to define what data a content editor can associate with the object
After you save the template, it can then be used to create content items in Sitecore 💥
Creating an Item In Sitecore using a Template
Items created from a template will be structured using the sections and fields you added. To create an item based on a template, in the Content tree
, right-click on a folder and select Create From Template
:
You can now create a content item based on the template:
How To Change The Template Of An Existing Sitecore Item
There are times when you may want to change the template of an existing Sitecore item. This is possible and simple:
Open the content item that you want to change. In the top ribbon, select the Configure
tab. In the Template
section, click on the Change
button. From here you can select a new template to use.
You should now have a solid understanding of Sitecore templates, what they are and how you can create content using them. My main tip is to spend time and consider how you want to structure your project before creating lots of templates. The better you structure your projects, the better your experience with Sitecore will become. Happy Coding 🤘