Forum Discussion

Deleted's avatar
Deleted
Jan 15, 2025
Solved

Handelbars expession for PnP Search Result Webpart

Hi everybody,

 
I am completely new to Handlebars and trying to change PnP Search Results Webpart, so it opens Office files always in Desktop Apps.
Changing the default Sharepoint option for opening office files has no impact on PnP Search Result Webpart.

Through editing handlebars expressions in the PnP Webpart it is possible to force office files to open in Desktop Apps. With an if-Statement I need to define the desktop app matching for the FileTypes.

Could someone help with editing my code? I have no idea about handlebars syntax and how to setup the code in the right way. Can I Register a Handlebars-Helper right inside the code (see below) or should this Helper be defined somewhere else? Where?


Handlebars.registerHelper('eq', function (arg1, arg2) {
     return arg1 === arg2;
   });

{{#if (eq(slot item root.slots.FileType) "docx")}}
<a onclick="window.open('ms-word:nft|u|{{slot item root.slots.PreviewUrl}}');" href="javascript:void(0);">{{Title}}</a>
{{/if}}

{{#if (eq(slot item root.slots.FileType) "xlsx")}}
<a onclick="window.open('ms-excel:nft|u|{{slot item root.slots.PreviewUrl}}');" href="javascript:void(0);">{{Title}}</a>
{{/if}}

Resources