Tuesday, June 2, 2015

Tutorial: Creating a Sitecore 8 Website Part 2 - Template Creation

Introduction

If you began at part 1, you should now have a clean Sitecore 8 web site and visual studio solution. As we are building a travel web site, there will be two main types of items: content pages and travel destinations. Each of these item types will require a template so that content authors can enter the relevant information for each item instance.

Creating the templates

Log into Sitecore administration and open up the content editor. On the right hand menu expand the Templates item, right click it and create a Template Folder named TravelSite. By creating a folder to hold all custom templates, we make content syncing between environments easy. It also makes it easier for another developer to work with.

Right click the TravelSite folder and click Insert > New Template, do this 3 times and call them the following (they can all inherit from the standard template):
  • Common - This will have fields common across other item templates (such as title, metadata and navigation settings).
  • ContentPage - This is the generic content page
  • Destination - This is the travel destination
Your content tree to the left will now look like the following:

Now the field structure for the templates will be defined, enter the following details into the corresponding template (to keep things simple for right now, only the text and check box types are being used, however list types are ideal for fields like country).
  • Common

  • ContentPage

  • Destination
Click on each template and from the top Sitecore administration menu click Options > Standard values. This creates the standard values configuration for each template where we can set the default field settings, layouts and sublayouts. The folder structure should now look like the following:

On the Common __Standard Values file, set the Title field to "$name", this will default that title field to the name of the Sitecore item. The reason we use this field is because the title may want to be output to the page with special characters (apostrophe for example), and Sitecore does not allow these in item names. On the Common standard values file, tick the TopMenu and SideMenu check boxes.

We also need to assign the Common template as a base template to ContentPage and Destination. Select each item and from the top menu Options and then Base templates (Template). Now add the Common template and click Next to save the changes.


To give a nice user experience, we will also assign some icons to the ContentPage and Destination templates. This is done by selecting the templates, then from the top menu selecting Configure > Icon.
On both the ContentPage and Destination templates standard values we are going to set the insert options. This is what allows content authors to right click an item of this template type and have the templates appear there as insert-able right away. To set the insert options click on the standard values for ContentPage and Destination and from the Sitecore menu select Configure > Insert Options (Assign) and select both ContentPage and Destination Templates.

This will mean that whenever a user right clicks and selects insert on any item of template type ContentPage or Destination they will be able to insert another ContentPage or Destination without having to manually find the template in the tree.

A Sitecore package of the templates created, can be downloaded here. To install please see Using the package designer to sync Sitecore content between environments.

Next step

Now that the templates have been defined, we can move onto Part 3: Item Creation. Which involves creating the items in the content tree based on these template types. 

No comments:

Post a Comment