Create your own person search result display templates

Post date: Mar 07, 2014 5:9:41 PM

As part of a recent implementation, the business required that the search results for people looked different than the out-of-the-box look. Luckily, this is fairly simple to do as it really only entails creating your own display templates that you then utilize as part of your search results. Specifically, the business had the following requirements for the People Search Results and the Hover Panel:

Search Results

  • User Photo

  • Preferred Name

  • Job Title

  • Office

  • Desk Phone / Mobile Phone

Hover Panel

  • Additional Person Information to include

    • **(Info from user profile which was populated by AD which was populated by Oracle EBS):

    • Cost Center and Cost Center Name

    • Business Unit

    • Supervisor

  • Always include the following sections if anything is present:

    • Skills

    • Past Projects

    • Schools

How To

The first step is to make a copy of the standard display templates. Go to your display template page from your search results page (e.g. http://example.domain.com/sites/searchcenter/_layouts/15/DesignDisplayTemplates.aspx). From here, you can find the out-of-the-box people display templates and download them locally to your development machine. The files you are looking to download are "People Item" and "People Hover Panel" out seen in the following picture.

Once you have these files downloaded, go ahead and rename them and then open them up in an html editor. Within the editor, you can bring in new managed properties into the code by placing them in the <mso:ManagedPropertyMapping msdt:dt="string"> properties listing.

After all your properties that you wish to have utilized as part of this display template are included, you can then go to the body of the code where you will by default find a large number of variables which check the state of various properties. You can add additional variables that you may want to include in your code as well in this section. Please note that this is also where you set the url of your new Hover Panel that your making as well. One of the last variables, if not the last, is named by default 'hoverUrl'. Update the name to your new name. In my case, I replaced the substring of the url from "Item_Person_HoverPanel" to "Vaisala_Item_Person_HoverPanel" as seen here:

var hoverUrl = "~sitecollection/_catalogs/masterpage/Display Templates/Search/Vaisala_Item_Person_HoverPanel.js";

Your next step is to adjust the actual HTML code with the needed changes. As an example, I wished to include the work and mobile phone numbers on the same line. The following is the section of code that I added to accomplish this:

<!--#_

if(has_wkph == true && has_mobph == true) {

_#-->

<div id="WorkAndMobilePhoneField">

<!--#_

var encodedWkPh = $htmlEncode(ctx.CurrentItem.WorkPhone);

var displayWkPh = Srch.U.getSingleHHXMLNodeValue(hhProps, "workphone");

if ($isEmptyString(displayWkPh)) { displayWkPh = encodedWkPh }

var encodedMobPh = $htmlEncode(ctx.CurrentItem.MobilePhone);

var displayMobPh = Srch.U.getSingleHHXMLNodeValue(hhProps, "mobilephone");

if ($isEmptyString(displayMobPh)) { displayMobPh = encodedMobPh }

_#-->

<div id="WorkAndMobilePhoneValue" class="ms-srch-ellipsis" title="Phones"> Phone: _#= displayWkPh =#_ / Mobile: _#= displayMobPh =#_</div>

</div>

<!--#_

}

_#-->

Similarly, do the same with the Hover Panel display template. Once complete, you can upload these templates into the template library. I utilized SharePoint Designer for this step by going to the list of all display templates for the Search Center and choosing upload. Once the templates are uploaded, you will need to go into the SharePoint Display Template library and publish your new files.

Now that the new files are published, you now need to tell SharePoint Search to use these new templates to display your results. This is as easy as setting up a new result type rule for the site. You can go into the rules under the site settings or a direct link to

http://my.domain.com/sites/searchcenter/_layouts/15/manageresulttypes.aspx?level=site

Create a new result type rule so that when Local People Results are found, the results look like "your new display template". Here is what mine looked like:

Save all of your changes and you should now see your updated search results. In my case, my search results look like this:

**Sorry, but I had to blur out some of the text, but you get the idea here.