none
How to create a Display template for people search results RRS feed

  • Question

  • 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 9, 2012 9:14 AM Cellphone should be MobilePhone
    Friday, November 9, 2012 9:13 AM

Answers

  • 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 9, 2012 10:05 AM
    Friday, November 9, 2012 10:05 AM

All replies

  • 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 9, 2012 9:58 AM
    Friday, November 9, 2012 9:16 AM
  • 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 9, 2012 10:05 AM
    Friday, November 9, 2012 10:05 AM
  • 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

    Thursday, January 31, 2013 9:05 AM
  • 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
    Thursday, January 31, 2013 3:34 PM
  • 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.

    Friday, February 1, 2013 7:49 AM
  • 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

    Monday, February 4, 2013 9:12 AM
  • 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

    Monday, February 4, 2013 9:27 AM
  • You welcome :-)

    Glad you got i to work.

    Monday, February 4, 2013 9:28 AM
  • Wow . it saved my lot of time.

    thank you.

    Monday, February 4, 2013 4:34 PM
  • 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?
    Wednesday, September 25, 2013 4:05 PM
  • 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

    Wednesday, November 20, 2013 11:59 AM
  • 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

    Monday, February 10, 2014 4:20 PM
  • 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 ....

    Tuesday, February 25, 2014 11:49 AM
  • 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

    Thursday, April 2, 2015 3:00 AM
  • Hi

    I would start by proving that your test users do have work email properties populated in AD - I have worked with clients where this is not always the case.

    Next the mapping in user profile service. Again, your mapped attribute correctly references the above AD property. I think there is more the one email property in AD so best to get the correct one. 

    Next, try a full profile sync, just to be on the safe side.  Thereafter, it is about checking the display template logic including the managed Property entry at the top of the display template which you have not included in your code snippet.

    Finally,  I always make changes to user related  schema and or change display templates at the Enterprise Search service level and not in the Search site collection or where ever you maybe  hosting the search results.

    Good luck 

    Daniel


    Freelance consultant

    Thursday, April 2, 2015 7:37 AM
  • 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.

    Tuesday, April 7, 2015 9:40 AM