This is a blog post in the series "How to change how search results are displayed." To demonstrate how you can customize your search results, I'll use examples from an internal Microsoft Search Center.
For an overview of the blog post in this series, go to How to change the way search results are displayed in SharePoint Server 2013.
In my previous blog post, I showed you how to display values from custom managed properties with hit highlighting, and get automatically improved relevancy based on end-user click behavior. In this blog we'll learn:
How to decide which hover panel display template to modify
Before we do anything, let's first refresh our memories on how the different display templates are connected:
By default, the rendering of the hover panel is done by the three common hover panel display templates. The illustration below shows how the common hover panel display templates were used to render the default hover panel in my Search Center scenario.
To make life as easy as possible for yourself when adding custom properties to your hover panel, you should leave these three common hover panel display templates as is, and instead, concentrate on the result type specific hover panel display template (highlighted in the illustration below). That’s what I did in my Search Center scenario, and it’s what I’ll show you in this blog post.
I completely understand if this sounds confusing, but I’ll walk you through all the steps in the next two sections. So let’s just get started!
How to copy an existing hover panel display template
Remember that when I created the custom item display template TechNet content, I started by copying the item display template named Item_Default. The Item_Default display template contains a reference to the Item_Default_HoverPanel hover panel display template. Because I copied the Item_Default display template, my TechNet content display template also contains a reference to the Item_Default_HoverPanel.
I wanted to use the Item_Default_HoverPanel hover panel display template as a basis when adding custom properties to my hover panel, so in my mapped network drive, I copied the Item_Default_HoverPanel display template…
… and gave it a new name: TechNet_Content_HoverPanel.
Now that I had created a custom hover panel display template, it was time to move on to the exciting stuff: adding custom properties.
How to modify a hover panel display template to show values from custom managed properties
In my Search Center scenario, the default hover panel contained almost no additional information about the search result.
I wanted to add the values from the following four site columns to the hover panel:
The screenshot below shows how these values are maintained for an individual item in our internal list.
When adding custom properties to a hover panel, you have to add them to the item display template (highlighted in the illustration below). I will say this again, because this is not really intuitive: When adding custom properties to a hover panel, you have to add them to the item display template.
To display custom properties in the hover panel, here’s what you should do:
In my scenario, I added four managed properties to the TechNet content item display template.
This alert is displayed because we have added new managed properties to an item display template (we did this in step 2). To update the result types with the newly added managed properties, choose Update.
IMPORTANT! If you don't do the update, the newly added managed properties will not display in your hover panel.
By doing a new search and hovering over a search result, I saw that the four custom properties were now displayed. Nice!
However, I wasn’t quite satisfied. The values for Internal Writer and Submission Contact were displayed differently. The screenshot might not show it clearly, but hopefully you can see that the value for Internal Writer was displayed nicely, but the value for Submission Contact was very long and contained an ugly GUID. Both these two values come from a site column of type Person or Group. The difference is that in the site column settings, Internal Writer is configured to show Name, whereas Submission Contact is configured to show Name (with presence).
To make Submission Contact display correctly, I copied the HP.GetAuthorsHtml method that is used by the Item_CommonHoverPanel_Body display template to display authors.
And now the hover panel was starting to look really good.
But to make the hover panel even more helpful, I wanted to add an action to the bottom of the hover panel. I’ll show you how to do this this in my next blog post.
Next blog post in this seriesHow to add a custom action to the hover panel