Understanding Sitecore templates will probably be your first challenge. In every other CMS system, a template is something that is usually associated with an object that defines how something will look, normally a page that can be created within the editor.. however, in Sitecore, this isn’t’ the case.
When I first started to work with Sitecore, I found it easier to refer to templates as data-templates instead. A Sitecore template has the same concept as a class in.NET. It’s an object that you use to define something. Like C# classes, templates are made up of fields. These fields can be text, numbers, dates, rich-text etc…
Templates are the building blocks of every Sitecore project. Unlike the normal CMS terminology, a Sitecore template represents the data items that define the properties of our pages and renderings. In today’s tutorial, I’m going to cover the how to create a template in Sitecore and use it on your website.
Creating a Sitecore Template
To find a list of the templates in your project, open up your Sitecore content editor and navigate to the templates section ‘/sitecore/templates’ :
In here you will find a list of default Sitecore system templates. On a usual project, it is usually good practice to create a new folder called ‘Sites’ or ‘User Defined’.
/sitecore/templates/User Defined/[Website Name]
In your ‘Sites folder, you then create a new folder called your website’s name. Splitting up your templates is a good idea in case you use things like object mappers and editor permissions. The more you split your controller up, the greater control you have on your Sitecore instance.
If you run two websites in your Sitecore instance and want to share pages, or blocks between the two, then most people define these templates in:
To create a new template on your new ‘My Website’ folder, right click and select ‘New Template’
From here you will be presented with the ‘New Template’ screen. The useful thing about this screen is the ability to base your template off of another template. This can be really useful if you want to add shared data between your pages. For example (this isn’t the way I’d structure a project) you could create a base page that contains everything you need for your header and footer, for each page template you define inherit from the base page to import the header and footer settings. This technique can save a lot of duplication when you start building your website in anger!
By default, the standard base Sitecore template is the ‘standard template’ and any new template you create will default to:
After you decide the name and the base template, you need to decide where in the content tree to save your template. As mentioned above I always prefer to organise my controls in a website folder with-in individual folders.
After you create your template, you can start doing useful things with it. You can now add sections and fields using the ‘Builder’ tab. As the names suggest these will be the items that will define what properties a content editor can add about a page. Template sections are used to group similar fields together, fields are the properties to define data with. 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 have the template sections and fields defined in the template. To create an item based on a template, in the Content tree, if you right click on a folder and select ‘Create From Template’
You should see be able to add content to your new template. As you can see from the screenshot, the properties defined in the template are now available for a content editor to add data to.
How To Change The Template Of An Existing Sitecore Item
There are times when you may want to change the template of an existing site core item. Doing this is simple.
Click on the item you want to change, and in the top ribbon, select the ‘Configure’ tab. In the ‘Template’ section, click ‘Change’. From here you can then select a new template to use.
In today’s guide, we’ve covered the basics of what a template is and how you can create one in Sitecore. When dealing with items in the content tree, it is a good idea to spend some time and consider how you want to structure your project. The better you structure your projects, the better your experience with Sitecore will become.