Display Templates Archives : Binary Bits https://blog.binarybits.net/tag/display-templates/ Bits & Pieces - A blog by Kannan Balasubramanian Wed, 17 May 2017 07:52:49 +0000 en-GB hourly 1 https://wordpress.org/?v=6.5.2 File Icons in SharePoint Search Results using Display Template https://blog.binarybits.net/file-icons-sharepoint-search-results-using-display-template/ https://blog.binarybits.net/file-icons-sharepoint-search-results-using-display-template/#respond Mon, 11 Jul 2016 05:44:37 +0000 https://blog.binarybits.net/?p=777 In SharePoint 2013 search results, the icon for a file type like .msg, .txt shows up as .html icon. In SharePoint 2010 this was overcome by mapping the icon file type in DocIcon.xml at WFE Servers. But now since access to WFE servers are restricted in on-prem environment and no access in O-365 environment, the […]

The post File Icons in SharePoint Search Results using Display Template appeared first on Binary Bits.

]]>
In SharePoint 2013 search results, the icon for a file type like .msg, .txt shows up as .html icon.
In SharePoint 2010 this was overcome by mapping the icon file type in DocIcon.xml at WFE Servers.

But now since access to WFE servers are restricted in on-prem environment and no access in O-365 environment, the only solution available is to do the following.

  1. Edit the existing display template (I use custom display template with results shown in table and following is based on that) or create a new template for existing for the following located at (SiteCollection/All Files/_catalogs/masterpage/Display Templates/Search) accessible by using SharePoint Designer.
    1. xxxSearchTableResults.html
    2. xxxSearchTableItem.html
  2. Add the following codes and it should show correct icons.

Search Results Display Template:

<div style="width:15px;display:table-cell;text-align:left;font-weight:bold;padding: 5px 0px 4px 10px;">                                       
</div>

Search Item Display Template:

<div style="min-width:16px;max-width:16px;display: table-cell;white-space:nowrap;overflow:hidden;-ms-text-overflow:ellipsis;-o-text-overflow:ellipsis;text-overflow:ellipsis;">                                       
<!--#_
 var extObj = new Object();
extObj["FileExtension"] = ctx.CurrentItem.FileExtension;
 var iconUrl = SP.Utilities.HttpUtility.htmlEncode(Srch.U.ensureAllowedProtocol(Srch.U.getIconUrlByFileExtension(extObj, null)));
if(ctx.CurrentItem.IsContainer)
iconUrl = "/_layouts/15/images/icdocset.gif";
if(ctx.CurrentItem.FileExtension === "msg")
iconUrl = "/_layouts/15/images/icmsg.gif";
//console.log(ctx.CurrentItem.FileExtension);
 _#-->
<img id="_#= $htmlEncode(id + Srch.U.Ids.icon) =#_" onload="this.style.display='inline'" src='_#= iconUrl =#_' />
 </div>

Notes:
ctx.CurrentItem.FileExtension always return the file extension name which seems to match with the file name in the /_layouts/15/images/ folder.

For example msg = icmsg.gif or icmsg.png

Once done, the search results will show-up as following

Search-Icon

The post File Icons in SharePoint Search Results using Display Template appeared first on Binary Bits.

]]>
https://blog.binarybits.net/file-icons-sharepoint-search-results-using-display-template/feed/ 0