Condividi tramite


Upload display templates to all sites in your SharePoint Server 2013 farm using PowerShell

In SharePoint Server 2013, display templates are used to control how content is displayed in the Content Search Web Part and the Search Result Web Part. You can read more about how display templates work in the these blog post:

- Upload and apply display templates to the Content Search Web Part
- Understanding how search results are displayed

If you have created custom display temples, you have to upload them to the SharePoint sites where you want to apply them. If you only have a few sites in your SharePoint farm, you can easily do this by mapping your network drive, and dragging and dropping your custom display templates into the correct file directory. However, if you have a large number of sites in your farm, this process can be quite time consuming.

In this blog post, I’ll explain how you can upload display templates to all sites in your farm by using PowerShell scripts.

About the scripts

All display templates are located in Master Page Gallery --> Display Templates.

You can use one script to upload display templates to the Content Web Parts folder, and another to upload to the Search folder.

 

 

Upload display templates to the Content Web Parts folder

The display templates that are located in the Content Web Parts folder are used by the Content Search Web Part.

To upload display templates to the Content Web Parts folder to all sites in your farm, all you have to do is modify the UploadToContentWebParts script so that it contains the file path to where you have stored your custom display templates.

 

Then, run this script on the machine that hosts your SharePoint farm. Complete script is attached at bottom of the post.

 

Upload display templates to the Search folder

The display templates that are located in the Search folder are used by the Search Results Web Part. These display templates are connected to a result type.

The UploadToSearch script will upload your custom display templates to the Search folder to all sites in your farm, create new result types on all sites in your farm, and connect these result types to your custom display templates.

To do this, you have to modify the UploadToSearch with the following :

-          FileType match: FileType that the new result type should match.

-          Result type name: name of the new result type.

-          Full file path: full file path to where you have stored your custom display template.

 

Then, run this script on the machine that hosts your SharePoint farm.

 

IMPORTANT: You must include minimum two custom lines for the UploadToSearch script to run correct.

 

In the following example, I have modified the UploadToSearch script with two custom lines.

 

By running this script, my two custom display templates are uploaded to all sites in my farm.

 

Two new result sources are created on all sites in my farm. These new result sources are connected to my custom display templates.

 

 

ScriptSample.zip

Comments

  • Anonymous
    November 30, 2015
    Hi, Nice Blog.. , i have a query  " i have seen in my production env. its seem to be showing  item display template with hover panel ,but when i check with my dev or test sharepoint 2013 env. i m not getting small hover panel image, we have just upgrade SharePoint 2010 to SharePoint 2013..Production evn. and my dev and test was new.. ..