Thursday, April 18, 2024
HomeMicrosoft 365Customizing Search Result Display using Handlebars in PnP PowerShell

Customizing Search Result Display using Handlebars in PnP PowerShell

Effortlessly Create Multiple SharePoint Sites with PowerShell and PnP Framework

you will need to install the PnP PowerShell module and connect to your SharePoint site. Once you have done that, you can use the Set-PnPSearchConfiguration cmdlet to customize the search result display.

Here’s an example of how to customize the search result display using handlebars:

# Connect to your SharePoint site
Connect-PnPOnline -Url https://your-sharepoint-site-url.com

# Define the handlebars template for your search results
$template = '<div class="search-result">'
$template += '<h3>{{{Title}}}</h3>'
$template += '<p>{{{Description}}}</p>'
$template += '</div>'

# Set the search configuration to use the handlebars template
Set-PnPSearchConfiguration -CustomItemDisplayTemplate $template

In this example, the handlebars template defines a basic search result display with a title and description. You can customize the template to include additional fields or formatting as needed.

Once you have set the search configuration, your search results should be displayed using the handlebars template you defined

Most Popular