Tuesday, December 23, 2014

How to enable Content Search Web Part Display Templates for Search Result Web Part

By default the out of the box control and display templates have been marked to work with their respective web parts. You can however re-use the templates across both web parts, as long as you ensure any script dependency is fixed. For example the CSWP has a reference to _layouts/15/search.cbs.js which must be added to the page in order for the Search Result Web Part to use the CSWP display templates.

The good thing is that the CSWP display templates are installed even though you don’t have the CSWP available. Here are the steps you need to perform to use the “Two Lines” CSWP display template with the Search Result Web Part.
  • Navigate to site settings
  • Under “Web Designer Galleries” go to “Master Pages”
  • Go to the “Display Templates” folder
  • Go to the “Content Web Parts” and you should see this listing

  • Edit properties on “Control_List.js”
  • Check “Search Results”

  • Click “Save”
  • Apply the same property change to “Item_TwoLines.js”
You have now enabled the display templates for use in the Search Result Web Part, and it’s time to set it up on a page.
Navigate to the page where you want the listing. In this sample I’m using the home page of a team site.
  • Edit the page
  • Insert a “Script Editor” web part on the page
  • Add a reference to search.cbs.js by adding <script type="text/javascript" src="/_layouts/15/search.cbs.js"></script> If you skip this part the display template will get an error with a missing reference to a javascript function.

  • Insert a “Search Result” web part below the “Script Editor” web part
  • Edit the web part properties of the “Search Result” web part and click “Change query”
  • Click “Switch to Quick Mode” (for this demo) and you should see this settings page
  • Click “Ok”
  • Expand the “Display Templates” section on the web part properties and pick the control and display template previously enabled
  • Click “Ok” and save the page changes and you should see something similar to this


  1. Worked like a charm! Thank you very much for the detailed walkthrough, this will come in very handy.

    1. You might want to load the .js file via $includeScript in the control template instead of a script part, but it shows the dependency, which was the key point. And hope it comes in handy some time :)

  2. How to use Display template/Item Template acorss WebApplication/SiteCollection Level ?

    1. You have to deploy them to all applicable site collections.

  3. Hi Mikael

    This is great, thanks for sharing.

    Just a quick note for readers who are attempting this on a publishing site. There is a HTML file associated with each .js file. The properties need to be editied on that file, not directly on the .js file.



  4. If your Microsoft subscription is not E3, E5, or SharePoint Online 2, you do not have access Content Search Web Part. But you can ask Microsoft for it here: https://office365.uservoice.com/forums/264636-general/suggestions/18776182-make-the-content-search-webpart-cswp-available-t