I have to create a custom display template for a Search Results Web Part which returns results in a tabular form.

I have created a custom template with a single row html table with six columns containing the relevent data. The problem is the data returned by the ctx.CurrentItem statements is in the wrong formats. The date strings include time and the user strings include GUID and email address.

In a list view I would use a calculated field and build a formula to reformat the data so it displays the way I want it but I am not sure how to do this in an html table.

Can anyone tell me hwo to go about this?


2 Answers 2


You have to create an Item Template for the rows and a Control Template for the surrounding "Table". You don't need to use an actual table as you could also achieve this with DIVs.



The easiest way to do this is to modify the XSLT behind your display template. Since you created a custom template, I assume you already know how to do that.

To format a date field so that it displays the date only, you would use a format flag like this:

<xsl:value-of select="ddwrt:FormatDate(string(@EventDate), 1033, 5)" />

To display only a specific part of a person (user) field, call the value of that part only:

<xsl:value-of select="@AssignedTo.Title" /> or <xsl:value-of select="@AssignedTo.Email" />


Keep in mind - accessing the XSL behind your search results is different depending on what version of SharePoint you're on. If it's SP2010, you can edit the XSL directly by editing the web part.

2010 - https://msdn.microsoft.com/en-us/library/office/ms544191(v=office.14).aspx

For SP2013, the XSL is determined by which Item Display Template is being used.

2013 - https://support.office.com/en-au/article/Change-how-search-results-look-by-using-result-types-and-display-templates-0fc83eeb-28c8-4f65-afe3-0ee515296a9d

  • This isn't a Content Query Web Part, Its a Search Results Web Part. The results are styled with HTML, not XSLT. Unless you know a way to get SharePoint to style the results with XSLT instead I need a solution based on HTML/CSS/JScript
    – JonS
    Feb 26, 2015 at 9:00
  • Search results still use XSL behind the scenes. Added a link for each version of SharePoint.
    – Omegacron
    Feb 26, 2015 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.