SharePoint 2013: Design Manager - Use of Display Templates

SharePoint 2013: Design Manager - Use of Display Templates



Display Templates ?

If you've never heard of, it is quite normal, as it is new in SharePoint 2013. These Display Templates can dynamically change the display of search results, making them particularly match "Result Types".

The use of XSLT ? Done !

These Display Templates allow you to free yourself from the use of XSLT, since you can edit using the HTML / JavaScript / CSS trio. For those who have already handled (or experienced) the XSLT, it’s a good news.

Access to the Display Templates

You can access to Display Templates via:

  • The Design Manager, "Edit Display Templates" link - To view the list of templates,
  • The "Site Settings", "Master pages and page layouts" link - To add / edit a template.

I will detail here this second link.

Click on the "Display Templates" folder:

I choose here to open the "Search" folder:

You will find the Display Templates, each being defined by:

  • A HTML file: its definition, this is the file you need to edit (or create) to define views,
  • A js (JavaScript) file: this file is generated by SharePoint through the HTML file. You must not edit this file, it is always the HTML file you need to modify, SharePoint converting the js file on the fly.

File names are relatively speaking, above we can deduce that the Display template controls the display of Word documents "Hover Panel".

We will change this "Hover Panel" later in this article:

Use of "Result Types"

The "Display Templates" are closely related to another SharePoint 2013 new functionality: the "Result Types". In summary, a "Result Type" it is a set of rules that are used when displaying search results.

When you run a search, and when the results are displayed on the results page, each result is verified to see if it meets one of the rules: If this is the case, the "Display Template" associated with this rule (this "Result Type") is used to display the item.

For example, you can define a rule (a Result Type) that combines a display (a Display Template) especially for Word documents containing "SharePoint" in their title - This is the example that will be used later in this article.

Example of use

In this example, the scenario is that you need to display a customized "Hover Panel" for any Word document containing "SharePoint" in its title.

To do this, I will:

  • Duplicate the "Item_Word_HoverPanel.html" file to customize the Hover Panel (I added a text "Submit for approval" at the bottom of the window - it's late, I lack inspiration J))
  • Duplicate the "Item_Word.html" file to use the above file.

The steps are as follows:

1. Download the "Item_Word_HoverPanel.html” file

2. Modify it and upload it again in the gallery as "Item_Word_HoverPanel_SPAsipe.html"

3. Fill the properties (note the ‘Target Control Type" parameter)



4. Similarly, download "Item_Word.html" and rename it "Item_Word_SPAsipe.html".

Open the file with an extremely powerful tool (Notepad for example) and change the link to the customized "Hover Panel" (note that this is the. Js file that is referenced, not the html one).

5. Upload this file in the gallery, and note that the Js files associated with the html files have been generated during the upload.

6. If you start the Design Manager, "Edit Display Templates" link, you see that the two html files are marked as having been converted.

7. It is now time to create a Result Type for our needs.

Go to the Site Settings, click on “Result Types”.

8. The list of existing Result Types appears, click on "New Result Type"

9. Conditions must be defined: here we want the items using our new "Hover Panel" to be Word documents having "SharePoint" in their title.

10. It only remains to associate this condition with our template

11. The Result Type is created

Result

1. The document chosen for the test has "SharePoint" in its title, and you can see that the customized Hover Panel that displays

2. If I choose an another Word document, the default “Hover Panel" displays

Webparts parameters

The Display Templates are configurable (among other places) in the "Search Results" webpart properties:

By default the rules (Result Types) are used, but you can change this behavior.

Conclusion

Beyond this example a bit trivial, these features allow much opportunities, especially for future "search-driven" applications. Personally, I find this feature very interesting.

See Also

This article is part of a series of articles dedicated to the Design Manager in SharePoint 2013. They are actually written in French and hosted on my blog, but I will translate and transfer them on the TechNet Wiki.

Sort by: Published Date | Most Recent | Most Useful
Comments
Page 1 of 1 (5 items)