Tuesday, 4 April 2017

Getting the current item's icon path in Search Display Template Code

To show the file icon for the results in search display template, below code can be used.

// Get the current path of the file
var currentItem = ctx.CurrentItem.Path;
// Get the file extension from path 
Var ext = currentItem.split(",")[0].split(".").pop().split('?')[0];
// Add this extension in an object
Var  extObject = new Object();
extObject["FileExtension"] = ext;
// Get the icon url using below getIconUrlByFileExtension method
var iconUrl = SP.Utilities.HttpUtility.htmlEncode(Srch.U.ensureAllowedProtocol(Srch.U.getIconUrlByFileExtension(extObject, null)));

No comments:

Query List/Document Library in Specific Folder

To query SharePoint List or Document Library in specific Folder “ FolderServerRelativeUrl ” as part of the CAML Query Code Snippet ...