Steps To Create Custom Display Templates In SharePoint 2013

Introduction

Display templates in SharePoint 2013 are the templates used in Web parts, which are used to show the results of a query made to the search index. Display templates control which managed properties are shown in the search results and how they appear in the Web Part. Each display template is made of two files- HTML version of the display template, which you can edit in your HTML editor and a .js file, which SharePoint uses, which converted from the HTML file. In this article, I will explain, how to create custom display templates in SharePoint 2013.

Prerequisites

  1. Go to SharePoint 2013 central administration site.
  2. Create a new publishing portal site collection.



  3. Create static HTML page design with CSS, JavaScript for the display template.

Create Display Template

  1. Open SharePoint publishing site we created.
  2. Go to Site Action -> Site Action.

    Template

  3. Click “Master pages and page layouts” under Web Design Galleries.

    Template

  4. Click Display Templates in master page gallery.

    Template

  5. Different types of display templates are visible. Click type of display template, which we want to create. In this example, we are going to create search display template.

    Template

  6. The existing search display template will open. It will contain both HTML and the corresponding JavaScript template file.

    Template

  7. Click Control_SearchResults.html template file and download a copy.

    Template

  8. Rename the downloaded file as Control_SearchResults_Custon.html. Open the control template file in any of your preferred editors such as SharePoint Designer and customize the file, as per our need.

    Template

  9. Upload Control_SearchResults_Custon.html to the search display template.+

    Template

  10. Select the Content Type, Name, Title, Description, Target Control Type as a search result.

    Template

  11. After upload completes, it will create a corresponding .js file automatically.



  12. Click HTML file and publish it as a major version, while .JS file will automatically publish as a major version.



  13. Click on Item_Default.html template file and download a copy.



  14. Rename the downloaded file as Item_Default _Custon.html. Open the Item template file in any of your preferred editors such as SharePoint Designer and customize the file, as per your need.

    Template

  15. Uplaod Item_Default _Custon.html to search the display template.



  16. Select the Content Type, Name, Title, Description, Target Control Type as the search result.



  17. After upload completes, it will create the corresponding .js file automatically.



  18. Click on HTML file and publish it as a major version, while .JS file will automatically publish as a major version.



  19. Create new SharePoint publishing page and add Search Results Web part under Search group.



  20. Click on search Web part and Edit Web part.



  21. Select our custom control display template.



  22. Select our custom item display template.

    template

  23. Click apply and OK on Web part properties. Save & publish the page.
  24. Search result Web part will appear with our custom control and item display template.


Summary

Thus, you have learned how to create custom display templates in SharePoint 2013.

Up Next
    Ebook Download
    View all
    Learn
    View all