SharePoint Search: Custom Display Template with Preview inside Hover Panel

HoverpanelSharePointSearch

There are a lot of post how to create a custom display template for SharePoint Search. Today i would like to show a how you can add the default hover panel with the preview of document content inside. So this post intends not to customize the hover panel but rather include the default hover panel with preview of your documents in your custom search display template.

Prequerisites

First of all i assume you created your custom display template. If not, let me share here some posts which lead you through the process of creating one.

[1] Microsoft Blog

[2] How To Create Custom Display Templates For SharePoint Search by Prashant Bansal

[3] 10 Tips and Tricks by Elios Struyf

Well now we have our custom Display template.

In order to get also the cool hover panel with preview in our search results respective in our custom display template we simply have to check a few things.

Activating default hover panel with Preview of documents

If you copied the item_default.html file you will realize that there is a hover panel inside. But this hover panel does not show the preview. If you compare the item_default.html file with item_word.html file you see some differences.

#1 Difference: Managed Property Mapping

Item_Default.html

<mso:ManagedPropertyMapping msdt:dt=”string”>’Title’:’Title’,’Path’:’Path’,’Description’:’Description’,’EditorOWSUSER’:’EditorOWSUSER’,’LastModifiedTime’:’LastModifiedTime’,’CollapsingStatus’:’CollapsingStatus’,’DocId’:’DocId’,’HitHighlightedSummary’:’HitHighlightedSummary’,’HitHighlightedProperties’:’HitHighlightedProperties’,’FileExtension’:’FileExtension’,’ViewsLifeTime’:’ViewsLifeTime’,’ParentLink’:’ParentLink’,’FileType’:’FileType’,’IsContainer’:’IsContainer’,’SecondaryFileExtension’:’SecondaryFileExtension’,’DisplayAuthor’:’DisplayAuthor'</mso:ManagedPropertyMapping>

Item_Word.html

<mso:ManagedPropertyMapping msdt:dt=”string”>’Title’:’Title’,’Path’:’Path’,’Description’:’Description’,’EditorOWSUSER’:’EditorOWSUSER’,’LastModifiedTime’:’LastModifiedTime’,’CollapsingStatus’:’CollapsingStatus’,’DocId’:’DocId’,’HitHighlightedSummary’:’HitHighlightedSummary’,’HitHighlightedProperties’:’HitHighlightedProperties’,’FileExtension’:’FileExtension’,’ViewsLifeTime’:’ViewsLifeTime’,’ParentLink’:’ParentLink’,’FileType’:’FileType’,’IsContainer’:’IsContainer’,’SecondaryFileExtension’:’SecondaryFileExtension’,’DisplayAuthor’:’DisplayAuthor’,‘ServerRedirectedURL’:’ServerRedirectedURL’,’SectionNames’:’SectionNames’,’SectionIndexes’:’SectionIndexes’,’ServerRedirectedEmbedURL’:’ServerRedirectedEmbedURL’,’ServerRedirectedPreviewURL’:’ServerRedirectedPreviewURL’</mso:ManagedPropertyMapping>

Here we see the differences. There properties mapped which are used for the hover panel preview.

#2 Difference: Connected

Item_Default.html

var hoverId = id + Srch.U.Ids.hover;
var hoverUrl = “~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_Default_HoverPanel.js”;

Item_Word.html

var hoverId = id + Srch.U.Ids.hover;
var hoverUrl = “~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_Word_HoverPanel.js”;

This difference is also important. In this Hover Panel the preview is integrated.

Conclusion

So if you like to get the standard hover panel inside your custom search display template, you should add the necessary managed property mappings and of course switch to the right hover panel.

So here is the display template html basic which shows the preview inside the hover panel

[sourcecode language=”csharp”]



Word Item



_#=ctx.RenderBody(ctx)=#_


[/sourcecode]

Now your search results should display the preview like this:

HoverpanelSharePointSearch

Important note: You need for the preview of documents Office Online Server or previous versions.

The article or information provided here represents completely my own personal view & thought. It is recommended to test the content or scripts of the site in the lab, before making use in the production environment & use it completely at your own risk. The articles, scripts, suggestions or tricks published on the site are provided AS-IS with no warranties or guarantees and confers no rights.

About Karsten Schneider 312 Articles
Consultant for Microsoft 365 Applications with a strong focus in Teams, SharePoint Online, OneDrive for Business as well as PowerPlatform with PowerApps, Flow and PowerBI. I provide Workshops for Governance & Security in Office 365 and Development of Solutions in the area of Collaboration and Teamwork based on Microsoft 365 and Azure Cloud Solutions. In his free time he tries to collect tipps and worthy experience in this blog.

2 Comments

Leave a Reply

Your email address will not be published.


*