I am working on a Search result web-part, which should show documents from multiple document libraries. now i am trying to display the FileType icon beside the items. so i tried the following appraoch inside the display template:-
Fist i get the FileType for the document:-
var ft = $getItemValue(ctx, "FileType");
var iconURL = String.format('/_layouts/images/ic{0}.gif',ft)
then i render the src
as follow:-
<img src="_#= iconURL =#_" />
now the above appraoch has render icons for HTML , png images correctly. but fail to do so for icons related to MS word,pdf,xls.. now i check the actual path and seems so icons will have .gif
format while other will have .png
format, here are some icons paths:-
/_layouts/15/images/icpdf.png
/_layouts/15/images/ichtm.gif
/_layouts/15/images/icxlsx.png
/_layouts/15/images/icxls.png
/_layouts/15/images/icpng.gif
/_layouts/15/images/icdocx.png
so can anyone adivce if there is a way to show the icon file type inside the Search result webpart, which will work for all the types (with .png or with .gif)? Thanks