How to create a Three Lines Search Display Template

Before starting ensure the SharePoint Server Publishing Infrastructure site collection feature is activated:

1.  Access SharePoint Designer 2013. Open the site to add a new search display template.

2.  Click on “All Files” and “_catalogs” and “masterpage” and “Display Templates” and “Content Web Parts”:

SharePoint Designer 2013 Display Templates

3.  Select the display template to base the new display template on. In this example I have created a new display template based on the “Item_TwoLines.html” file. Right-click and select “Copy”. Right-click and select “Paste”. (Note: The JavaScript pair file is created automatically).

4.  Select the copied item and rename it e.g. “Item_ThreeLines.html”. Wait for the JavaScript to correctly copy (use the Refresh function). Ensuring the new renamed html item is selected, right-click and select “Check Out”.

5.  With the item selected right-click and select “Edit File in Advanced Mode”. The Advanced Editor displays the HTML.

The updated “Item_ThreeLines.html” appears as below. The highlighted elements indicate what has been added to the Item_TwoLines.html code:

<html xmlns:mso=”urn:schemas-microsoft-com:office:office” xmlns:msdt=”uuid:C2F41010-65B3-11d1-A29F-00AA00C14882″>
<title>Three lines</title>
<!–[if gte mso 9]><xml>
<mso:TemplateHidden msdt:dt=”string”>0</mso:TemplateHidden>
<mso:ManagedPropertyMapping msdt:dt=”string”>&#39;Link URL&#39;{Link URL}:&#39;Path&#39;,&#39;Line 1&#39;{Line 1}:&#39;Title&#39;,&#39;Line 2&#39;{Line 2}:&#39;Title&#39;,&#39;Line 3&#39;{Line 3}:&#39;&#39;,&#39;FileExtension&#39;,&#39;SecondaryFileExtension&#39;</mso:ManagedPropertyMapping>
<mso:MasterPageDescription msdt:dt=”string”>This Item Display Template will show a small thumbnail icon next to a hyperlink of the item title, with an additional line that is available for a custom managed property.</mso:MasterPageDescription>
<mso:ContentTypeId msdt:dt=”string”>0x0101002039C03B61C64EC4A04F5361F385106603</mso:ContentTypeId>
<mso:TargetControlType msdt:dt=”string”>;#Content Web Parts;#</mso:TargetControlType>
<mso:HtmlDesignAssociated msdt:dt=”string”>1</mso:HtmlDesignAssociated>
<mso:HtmlDesignStatusAndPreview msdt:dt=”string”>http://hsweb01/sites/navigate/_catalogs/masterpage/Display Templates/Content Web Parts/Item_ThreeLines.html, Conversion successful.</mso:HtmlDesignStatusAndPreview>
<mso:HtmlDesignConversionSucceeded msdt:dt=”string”>True</mso:HtmlDesignConversionSucceeded>
Warning: Do not try to add HTML to this section. Only the contents of the first <div>
inside the <body> tag will be used while executing Display Template code. Any HTML that
you add to this section will NOT become part of your Display Template.
<script> $includeLanguageScript(this.url, “~sitecollection/_catalogs/masterpage/Display Templates/Language Files/{Locale}/CustomStrings.js”);
Use the div below to author your Display Template. Here are some things to keep in mind:
* Surround any JavaScript logic as shown below using a “pound underscore” (#_ … _#) token
inside a comment.
* Use the values assigned to your variables using an “underscore pound equals”
(_#= … =#_) token.
<div id=”ThreeLines“>
var encodedId = $htmlEncode(ctx.ClientControl.get_nextUniqueId() + “_3lines_”);
var linkURL = $getItemValue(ctx, “Link URL”);
var iconURL = Srch.ContentBySearch.getIconSourceFromItem(ctx.CurrentItem);
var line1 = $getItemValue(ctx, “Line 1”);
var line2 = $getItemValue(ctx, “Line 2”);
var line3 = $getItemValue(ctx, “Line 3”);
var containerId = encodedId + “container”;
var pictureLinkId = encodedId + “pictureLink”;
var pictureId = encodedId + “picture”;
var dataContainerId = encodedId + “dataContainer”;
var line1LinkId = encodedId + “line1Link”;
var line1Id = encodedId + “line1”;
var line2Id = encodedId + “line2”;
var line3Id = encodedId + “line3”;
<div class=”cbs-Item” id=”_#= containerId =#_” data-displaytemplate=”Item2Lines”>
<a class=”cbs-ItemLink” title=”_#= $htmlEncode(line1.defaultValueRenderer(line1)) =#_” id=”_#= pictureLinkId =#_”>
<img class=”cbs-Thumbnail” src=”_#= $urlHtmlEncode(iconURL) =#_” alt=”_#= $htmlEncode(line1.defaultValueRenderer(line1)) =#_” id=”_#= pictureId =#_” />
<div class=”cbs-Detail” id=”_#= dataContainerId =#_”>
<a class=”cbs-Line1Link ms-noWrap ms-displayBlock” href=”_#= linkURL =#_” title=”_#= $htmlEncode(line1.defaultValueRenderer(line1)) =#_” id=”_#= line1LinkId =#_”>_#= line1 =#_</a>
<div class=”cbs-Line2 ms-noWrap” title=”_#= $htmlEncode(line2.defaultValueRenderer(line2)) =#_” id=”_#= line2Id =#_”>_#= line2 =#_</div>
<div class=”cbs-Line2 ms-noWrap” title=”_#= $htmlEncode(line2.defaultValueRenderer(line3)) =#_” id=”_#= line3Id =#_”>_#= line3 =#_</div>

6.  Save the edited “Item_ThreeLines.html” file. Check In the file and publish as a Major Version.

7.  If updated correctly, the new Display Template will appear in the “Content Search” Web Part properties. Select the display template name e.g. “Three lines”, as shown below:

Content Search Web Part Display Template Properties

8.  Expand the “Property Mappings” and tick the “Change the mapping of managed properties…” tick box. Note that a Link URL and Line 1, Line 2, and Line 3 appear based on the HTML changes. Click the drop-down menus to select available managed properties. On my example I have chosen to display a custom managed property called “DEVBMSID”, Title and UIVersionStringOWSTEXT (Version Number).

9.  To ensure that the Content Search Web Part only displays relevant documents click on the “Change Query” button in the “Search Criteria” section. Use the Quick Mode query builder or switch to Advanced Mode and enter search syntax – see example below:

Content Search – Build Your Query

10. You can test the results before clicking the “OK” button to save the search. Note: Refiners and Sorting can also be defined.

11. Ensure the “Number of items to show” is set to a suitable number – otherwise not all search results will be displayed.

12. Finally click on the Content Search Web Part properties “OK” button to save all settings.