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

Hello,

I did the same with my new SharePoint 2013 (I would like to display the mobile phone too) but without any chance. Have you done anything else ?

This is my User Property "CellPhone" :
http://www.cladstrife.com/CellPhone_Prop.png

The ManagedPropertyMapping :

<mso:ManagedPropertyMapping msdt:dt="string">'AboutMe':'AboutMe','AccountName':'AccountName','BaseOfficeLocation':'BaseOfficeLocation','Department':'Department','HitHighlightedProperties':'HitHighlightedProperties','Interests':'Interests','JobTitle':'JobTitle','LastModifiedTime':'LastModifiedTime','Memberships':'Memberships','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','CellPhone':'CellPhone','HomePhone':'HomePhone'</mso:ManagedPropertyMapping>

The "if_exist" variable :

var has_cphone = !$isEmptyString(ctx.CurrentItem.CellPhone);

And the "display" code :

<!--#_ 
                        if(has_cphone == true) {
_#-->
                                            <div id="CPhoneField">
<!--#_ 
                                                var encodedCPhone = $htmlEncode(ctx.CurrentItem.CellPhone);
                                                var displayCPhone = Srch.U.getSingleHHXMLNodeValue(hhProps, "CellPhone");
                                                if ($isEmptyString(displayCPhone)) { displayCPhone = encodedCPhone}
_#--> 
                                                <div id="CPhoneValue" class="ms-srch-ellipsis" title="_#= encodedCPhone =#_"> Mobile: _#= displayCPhone =#_ </div>
                                            </div>
<!--#_ 
                                        }
_#-->

If I delete the test lines in the display code (if(has_cphone == true) it show "Mobile:" but without any mobile number.

Thanks for your help if any idea :)

Best regards

Gabriel

Free Windows Admin Tool Kit Click here and download it now
January 31st, 2013 9: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
January 31st, 2013 3:34pm

Hi Vindryn,

Thats weird. I remember I tried a few times before I actually got this to work. not sure if it works but did you change your "title" and "id" in the html aswell? Walked through my template again and here is what I changed when I created it:

1. Copied the Item_Person display template to a new one eg. Company_Item_Person.html

2. Changed the title in line 3 to "Company People Item"

2. Added the managed property mapping the field if its not there already (Line 13)

3. Changed the <div id="Item_Person"> to <div id="Company_Item_Person" (line 24)

4. Added the "has_MobilePhone" variable (line 40)

5. Copied the workphone section and pasted it in the end at line 122 replacing values with mobilephone instead.

6. edited search results page to use my new Company_Item_Person.html template

I remember I played around testing it so it will display eventhough no mobilephone number value was on the user property. Made things easier but it seems you do it correctly already when you can have it display in another template.

Hope this helps as I really cant see much difference comparing your code to mine.

Free Windows Admin Tool Kit Click here and download it now
February 1st, 2013 7:49am

Hi Vindryn,

Thats weird. I remember I tried a few times before I actually got this to work. not sure if it works but did you change your "title" and "id" in the html aswell? Walked through my template again and here is what I changed when I created it:

1. Copied the Item_Person display template to a new one eg. Company_Item_Person.html

2. Changed the title in line 3 to "Company People Item"

2. Added the managed property mapping the field if its not there already (Line 13)

3. Changed the <div id="Item_Person"> to <div id="Company_Item_Person" (line 24)

4. Added the "has_MobilePhone" variable (line 40)

5. Copied the workphone section and pasted it in the end at line 122 replacing values with mobilephone instead.

6. edited search results page to use my new Company_Item_Person.html template

I remember I played around testing it so it will display eventhough no mobilephone number value was on the user property. Made things easier but it seems you do it correctly already when you can have it display in another template.

Hope this helps as I really cant see much difference comparing your code to mine.

Hi Jan,

Thank you very much for your detailed answer. I will test it asap.

Best regards

February 4th, 2013 9:12am

Wow, it worked :)

I think the step that fixed the bug is the first "copy item_person to a new one". I was modifying the code directly on the base "item_person.html" Template.

I don't know exactly why but perhaps the base "item_person" has a bug.

many thanks for you help

Free Windows Admin Tool Kit Click here and download it now
February 4th, 2013 9:27am

You welcome :-)

Glad you got i to work.

February 4th, 2013 9:28am

Wow . it saved my lot of time.

thank you.

Free Windows Admin Tool Kit Click here and download it now
February 4th, 2013 4:34pm

Hi there. I am having the same issue. I have followed all these steps but it still won't display the mobile phone. Any other ideas?
September 25th, 2013 4:05pm

My experience.

First i tried to show the email changing Item_Person.html and it worked. Then I tried to show the workPhone, this was not mapped and i added it,  and this not show the phone. To fix it (like Vindryn answer), i copied the file and i changed the display template on the search results with the new one. It works!
 
Thanks to Vindryn and Jan

Free Windows Admin Tool Kit Click here and download it now
November 20th, 2013 11:59am

Hi,

I am trying to display the email address in the search results, i have copied the above steps but it fails (i did manage to get the phone number working?)

Also do you know how to hide the hover panel from the people search results?

And finally..Can you remove the hyperlink for the name (in search results) as we dont wish to use mysites (i have configured it for people search but dont want it to be visible\clickable).

Thanks

Nick

February 10th, 2014 4:20pm

Hi,

I am trying to display the email address in the search results, i have copied the above steps but it fails (i did manage to get the phone number working?)

Also do you know how to hide the hover panel from the people search results?

And finally..Can you remove the hyperlink for the name (in search results) as we dont wish to use mysites (i have configured it for people search but dont want it to be visible\clickable).

Thanks

Nick

I did the email the other day for my client and encoded the email hyperlink

I think the managedpropertymapping was already there.

<!--#_                                        if(has_email == true) {
_#-->
                                                  <div id="WorkEmail">


<!--#_                                             var encodedwemail = $htmlEncode(ctx.CurrentItem.WorkEmail);


                                                   var displaywemail = Srch.U.getSingleHHXMLNodeValue(hhProps, "WorkEmail");


                                                   if ($isEmptyString(displaywemail)) { displaywemail = encodedwemail }


_#--> 
                                                <!--DAN: old ver div id="WorkEmailValue" class="ms-srch-ellipsis" title="_#= encodedwemail =#_"> _#= displaywemail =#_ </div -->
                                            
                                                <a href="mailto:_#= encodedwemail =#_">_#= displaywemail =#_</a>  
                                            
                                            </div>
<!--#_                                         }
_#-->

I am now struggling with a couple custom AD attributes that are both mapped to individual term sets .. they are definitely in my people profile but are not appearing in my custom display template ... oh well ....

Free Windows Admin Tool Kit Click here and download it now
February 25th, 2014 11:49am

Hi Jan,

I had followed your step and now it can show office location and work phone normally. However, the work email still return NULL!!!

<!--#_
                                        if(has_email == true) {
_#-->
                                            <div id="WorkEmail">
<!--#_
                                                var encodedemail = $htmlEncode(ctx.CurrentItem.WorkEmail);
                                                var displayemail = Srch.U.getSingleHHXMLNodeValue(hhProps, "WorkEmail");
                                                if ($isEmptyString(displayemail)) { displayemail = encodedemail }
_#-->
                                                <div id="WorkEmailValue" class="ms-srch-ellipsis" title="_#= encodedemail =#_">Work email _#= displayemail =#_ </div>
                                            </div>
<!--#_
                                        }
_#-->

Could you please suggest me how to solve this problem?

Best regards

April 1st, 2015 11:03pm

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

Other recent topics Other recent topics