One of the most interesting features in SharePoint 2013 are the display templates. This blog post will describe how to customize a search display template in order to show the item created date.
So what are the steps involved in creating a new display template?
Let’s take it step by step.
Duplicating an existing display template
Open the site collection with SharePoint designer. Navigate to the Display Templates folder under _catalogs\masterpage\display templates. Here you will find some Folders that SharePoint uses to group Display Templates together.
The Word item template is in the Search folder. Make a copy of the Item_Word.html and rename it to ComperioItem_Word.html
Edit the title field so that your custom template has a different display name than the original one.
The <mso:CustomDocumentProperties> tag contains some properties of the template. Some important properties are:
TargetControlType – tells SharePoint what the template is used for (search results, web parts, filters)
ManagedPropertyMapping – contains a list of the managed properties that are or can be used by the current template
The <body> tag contains the rendering logic for the display template.
The template can only recognize the managed properties that are listed in the header. To use another managed property, add it here. We are using the Created property that displays the document created date.
Now we are going to manually link the display template to a result type, so that we can see that it works.
In order for SharePoint to use your custom template, it needs to know of it. So navigate to Site Actions – Site Settings and under Site Collection Administration choose Search Result Types. Create a New Result Type for your template like below:
Choose a Name
Choose Microsoft Word as content to match
Choose your custom display template
Now go to the results page and search for a word document. The results should display a date looking like this: