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
- Go to SharePoint 2013 central administration site.
- Create a new publishing portal site collection.
- Create static HTML page design with CSS, JavaScript for the display template.
Create Display Template
- Open SharePoint publishing site we created.
- Go to Site Action -> Site Action.
- Click “Master pages and page layouts” under Web Design Galleries.
- Click Display Templates in master page gallery.
- 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.
- The existing search display template will open. It will contain both HTML and the corresponding JavaScript template file.
- Click Control_SearchResults.html template file and download a copy.
- 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.
- Upload Control_SearchResults_Custon.html to the search display template.+
- Select the Content Type, Name, Title, Description, Target Control Type as a search result.
- After upload completes, it will create a corresponding .js file automatically.
- Click HTML file and publish it as a major version, while .JS file will automatically publish as a major version.
- Click on Item_Default.html template file and download a copy.
- 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.
- Uplaod Item_Default _Custon.html to search the display template.
- Select the Content Type, Name, Title, Description, Target Control Type as the search result.
- After upload completes, it will create the corresponding .js file automatically.
- Click on HTML file and publish it as a major version, while .JS file will automatically publish as a major version.
- Create new SharePoint publishing page and add Search Results Web part under Search group.
- Click on search Web part and Edit Web part.
- Select our custom control display template.
- Select our custom item display template.
- Click apply and OK on Web part properties. Save & publish the page.
- 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.