0

I've created a custom search result page using the PnP Modern Search web parts v4. I'm using the list template and I have file icons displaying, but I'd like to change these to my own custom icon.

The default template shows:

<div class="template--listItem--result">
   {{#if @root.properties.layoutProperties.showFileIcon}}
   {{#contains "['STS_Site','STS_Web']" (slot item @root.slots.contentclass)}}
         <pnp-iconfile class="template--listItem--icon" data-extension="{{slot item @root.slots.FileType}}" data-is-container="{{slot item @root.slots.IsFolder}}" data-image-url="{{item.SiteLogo}}" data-size="32" data-theme-variant="{{JSONstringify @root.theme}}"></pnp-iconfile> 
{{else}}
         <pnp-iconfile class="template--listItem--icon" data-extension="{{slot item @root.slots.FileType}}" data-is-container="{{slot item @root.slots.IsFolder}}" data-size="32" data-theme-variant="{{JSONstringify @root.theme}}"></pnp-iconfile>
    {{/contains}}
    {{/if}}

I attempted to change pnp-iconfile to pnp-img but this resulted in only displaying my image, without any of the other search result content (title, author, etc). Can someone please explain how I might change the icon?

Additionally, would it also be possible to use 2 icons, depending on a managed property? Would the below work, for example:

{{#if @root.properties.layoutProperties.showFileIcon}}
{{#contains 'TypeA' (slot item @root.slots.iconType)}}
    <pnp-icon ~ first icon image - not sure what content to place here yet ~> </pnp-icon>
{{else}}
    <pnp-icon ~ second icon image - not sure what content to place here yet ~> </pnp-icon>
{{/contains}}
{{/if}}
1
  • I resolved the first part of my question by editing a data-image-url field to my else statement. {{else}} <pnp-iconfile class="template--listItem--icon" data-extension="{{slot item @root.slots.FileType}}" data-is-container="{{slot item @root.slots.IsFolder}}" data-image-url="https://address-of-icon-file" data-size="32" data-theme-variant="{{JSONstringify @root.theme}}"></pnp-iconfile>
    – Ronnie
    Commented Mar 10, 2023 at 7:46

1 Answer 1

0

This is now working. I changed the default template to the following:

{{#if @root.properties.layoutProperties.showFileIcon}}
{{#contains 'String1' (slot item @root.slots.Summary)}}
     <pnp-iconfile class="template--listItem--icon" data-extension="{{slot item @root.slots.FileType}}" data-is-container="{{slot item @root.slots.IsFolder}}" data-image-url="https://test.sharepoint.com/sites/GDTest/Shared%20Documents/file1.ico" data-size="32" data-theme-variant="{{JSONstringify @root.theme}}"></pnp-iconfile> 
{{else}}
     <pnp-iconfile class="template--listItem--icon" data-extension="{{slot item @root.slots.FileType}}" data-is-container="{{slot item @root.slots.IsFolder}}" data-image-url="https://test.sharepoint.com/sites/GDTest/Shared%20Documents/file2.ico" data-size="32" data-theme-variant="{{JSONstringify @root.theme}}"></pnp-iconfile>
{{/contains}}
{{/if}}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.