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)));
// 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:
Post a Comment