How to create a Display template for people search results

Hi,

I've just installed Sharepoint 2013 and started to play around with it. Seems to be many improvements - among these are the ability to create Display templates.

On my publishing page there is a default "employee lookup" app which returns prefferred name, title and department as default when I try to search.

I would love to return mobile number aswell so I have tried to do the following:

I made a copy of Display _Catalogs/Masterpages/Display Templates/Search/Item_Person.html

Edited that one with the following:

1. Added 'MobilePhone':'MobilePhone' to the "Managed Property mapping" in the top of the html   document:

<mso:ManagedPropertyMapping msdt:dt="string">'AboutMe':'AboutMe','AccountName':'AccountName','BaseOfficeLocation':'BaseOfficeLocation','Department':'Department','HitHighlightedProperties':'HitHighlightedProperties','Interests':'Interests','JobTitle':'JobTitle','LastModifiedTime':'LastModifiedTime','Memberships':'Memberships','MobilePhone':'MobilePhone','PastProjects':'PastProjects','Path':'Path','PictureURL':'PictureURL','PreferredName':'PreferredName','Responsibilities':'Responsibilities','Schools':'Schools','ServiceApplicationID':'ServiceApplicationID','SipAddress':'SipAddress','Skills':'Skills','UserProfile_GUID':'UserProfile_GUID','WorkEmail':'WorkEmail','WorkId':'WorkId','YomiDisplayName':'YomiDisplayName'</mso:ManagedPropertyMapping>

2. Set a var in the <body> with:

var has_MobilePhone = !$isEmptyString(ctx.CurrentItem.MobilePhone);

Created the following based on "DepartmentField":

                                        if(has_MobilePhone == true) {
_#-->
                                            <div id="MobilephoneField">
<!--#_ 
                                                var encodedMobilePhone = $htmlEncode(ctx.CurrentItem.MobilePhone);
                                                var displayMobilePhone = Srch.U.getSingleHHXMLNodeValue(hhProps, "MobilePhone");
                                                if ($isEmptyString(displayMobilePhone)) { displayMobilePhone = encodedMobilePhone}
_#--> 
                                                <div id="MobilePhoneValue" class="ms-srch-ellipsis" title="_#= encodedMobilePhone =#_"> _#= displayMobilePhone =#_ </div>
                                            </div>
<!--#_ 
                                        }

Saved the document to the masterpage galary and edited the search result page to (people search core results webpart) to "use a single template to display items" and selected my display template.

Now the search result is still working but I get no mobile numbers to show up in the user info (only in the details which is default).

Anyone has some bright ideas of what i'm missing?. I'm not used to code (which might be the cause :-)). If you also have an idea on how to make the value of the number = Mobile: <mobilenumber>. So the "Mobile:" static text is displayed aswell.

Thanks a lot for your time.


  • Edited by Jan Knudsen Friday, November 09, 2012 9:14 AM Cellphone should be MobilePhone
November 9th, 2012 9:13am

Sometimes it helps to do this a few times so I must have made a typo somewhere the first time. My "Mobilephone" number is now displayed. All I need now is to have "Mobile:" infront of the number. Anyone?

Thanks again.


  • Edited by Jan Knudsen Friday, November 09, 2012 9:58 AM
Free Windows Admin Tool Kit Click here and download it now
November 9th, 2012 9:16am

Found that solution aswell. Hopefully this post can help others anyways :-)

Static text is inserted after the <div id>:

<div id="MobilePhoneValue" class="ms-srch-ellipsis" title="_#= encodedMobilePhone =#_"> Mobile: _#= displayMobilePhone =#_ </div>

  • Marked as answer by Jan Knudsen Friday, November 09, 2012 10:05 AM
November 9th, 2012 10:05am

It seems that I can display my CellPhone property if I configure the Search Results Web Part to "Use a single template to display items" (under the Dislay Templates section) with the Template "Common item body".

But the people Template is better to display people results (normal :)

It's a bug ?


  • Edited by Vindryn Thursday, January 31, 2013 3:35 PM
Free Windows Admin Tool Kit Click here and download it now
January 31st, 2013 3:34pm

Hi,

The code looks good as far as I can see, so my suggestion would be the same as Daniels. Check that the WorkEmail property actually has values on your test users and that those properties are crawled.

Hope you'll get it to work.

April 7th, 2015 5:41am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics