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



<html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882">
<head>
<title>Word Item</title>

<!--[if gte mso 9]><xml>
<mso:customdocumentproperties>
<mso:templatehidden msdt:dt="string">0</mso:templatehidden>
<mso:masterpagedescription msdt:dt="string">Displays a result tailored for a Microsoft Word document.</mso:masterpagedescription>
<mso:contenttypeid msdt:dt="string">0x0101002039C03B61C64EC4A04F5361F385106603</mso:contenttypeid>
<mso:targetcontroltype msdt:dt="string">;#SearchResults;#</mso:targetcontroltype>
<mso:htmldesignassociated msdt:dt="string">1</mso:htmldesignassociated>
<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>
</mso:customdocumentproperties>
</xml>< ![endif]-->
</head>
<body>
<div id="Item_Word">
<!--#_
if(!$isNull(ctx.CurrentItem) &amp;&amp; !$isNull(ctx.ClientControl)){
var id = ctx.ClientControl.get_nextUniqueId();
var itemId = id + Srch.U.Ids.item;
var hoverId = id + Srch.U.Ids.hover;
var hoverUrl = "~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_Word_HoverPanel.js";
$setResultItem(itemId, ctx.CurrentItem);
ctx.CurrentItem.csr_Icon = Srch.U.getIconUrlByFileExtension(ctx.CurrentItem);
ctx.CurrentItem.csr_OpenApp = "word";
ctx.currentItem_ShowHoverPanelCallback = Srch.U.getShowHoverPanelCallback(itemId, hoverId, hoverUrl);
ctx.currentItem_HideHoverPanelCallback = Srch.U.getHideHoverPanelCallback();
_#-->
<div id="_#= $htmlEncode(itemId) =#_" name="Item" data-displaytemplate="WordItem" class="ms-srch-item" onmouseover="_#= ctx.currentItem_ShowHoverPanelCallback =#_" onmouseout="_#= ctx.currentItem_HideHoverPanelCallback =#_">
_#=ctx.RenderBody(ctx)=#_
<div id="_#= $htmlEncode(hoverId) =#_" class="ms-srch-hover-outerContainer"></div>
</div>
<!--#_
}
_#-->
</div>
</body>
</html>


Now your search results should display the preview like this:

HoverpanelSharePointSearch

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.



Karsten Schneider
About Karsten Schneider 295 Articles
He is Consultant for SharePoint Solutions for collaboration, communication and business processes. He provides his customers applications based on standard features as well as development or combining the power of several microsoft tools like Dynamics CRM. In his free time he tries to collect tipps and worthy experience in this blog.

Be the first to comment

Leave a Reply

Your email address will not be published.


*