In SharePoint 2013 we have displayed templates to handle the display of search results in web parts. I would recommend to read this msdn article to understand display templates first.
I will give a walk-through on how do we customize a display template for a particular requirement (in this case to display e-mail address of person).
Prerequisites
Search should be configured and working in the system.
Solution
- Create a web part page “MySearch.aspx”, and added “Search Box” & “Search Results” web parts.
- Configure both the web parts that search box query goes to search result.
- Go to Site Settings, then Master Page Gallery, Display Templates and Search.
- Download “Item_Person.html” file, the display template for People Item.
- Change html to display Email – add the highlighted code as in the following:
Inserted text (after NameField div)
- < div id = ”EmailField” > < !–#_
- var encodedEmail = (has_email == true) ? $htmlEncode(ctx.CurrentItem.WorkEmail) : “No Email Available”;
- var displayEmail = Srch.U.getSingleHHXMLNodeValue(hhProps, “workemail”);
- if ($isEmptyString(displayEmail))
- {
- displayEmail = encodedEmail
- }
- _#– > < div id = ”EmailValue” > _# = displayEmail = #_ < /div>
- </div >
- Upload the updated file to display template library and publish the file.
- Go to the MySearch page, Edit Page and Edit ‘Search Results’ Web part.
- Under ‘Display Templates’, chose ‘Use a single template to display items’ and select ‘People Item’.
- Save and exit the page.
- Search name in search box, it should return email id with People data.