Issue with Dynamic Parameters in KQL for Highlighted Content Webpart

Hemant Kabra 65 Reputation points
2025-01-23T07:34:34.71+00:00

Dear Team,

I am currently using the Highlighted Content Webpart on a Modern SharePoint Site Collection and applying a custom query using KQL. My goal is to dynamically filter the data based on the metadata of the current page where the webpart is installed. Specifically, I am trying to use the following query:

filename:{Page.FileLeafRef}

However, it seems that such dynamic parameters are not working as expected. Could you please provide guidance on how I can use the page properties in the KQL within the Highlighted Content Webpart to dynamically filter the data based on the current page's properties?

Thank you for your assistance.

Microsoft 365
Microsoft 365
Formerly Office 365, is a line of subscription services offered by Microsoft which adds to and includes the Microsoft Office product line.
5,684 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
11,175 questions
{count} votes

Accepted answer
  1. Yanli Jiang - MSFT 28,796 Reputation points Microsoft Vendor
    2025-01-23T10:05:50.6+00:00

    Hi @Hemant Kabra ,

    Thank you for posting the thread on our forum.

    In the context of using the Highlighted Content Webpart with KQL, it appears that dynamic parameters like {Page.FileLeafRef} may not be supported directly within the KQL queries for filtering content. Instead, you might want to consider using other methods to achieve your goal.

    Here is a workaround for your reference:

    Using PnP Modern Search Webparts to achieve dynamic filtering based on the current page properties.

    1. Install the PnP Modern Search Webparts

    First, you need to install the PnP Modern Search Webparts to your SharePoint site collection. This will give you more flexible and powerful search functionality.

    Steps to Install:
    1. Download the PnP Modern Search Webparts package: Go to the PnP Modern Search GitHub repository and download the latest release package.
    2. Upload the Package to the App Catalog:
      • Go to your SharePoint Admin Center.
      • Navigate to Apps -> App Catalog.
      • Upload the downloaded package to the Apps for SharePoint library.
    3. Add the Webparts to your Site:
      • Go to the site collection where you want to use the web parts.
      • Click on the gear icon and select Add an app.
      • Find the PnP Modern Search Webparts app and add it to your site.

    2. Configure the PnP Modern Search Webparts

    Now that you have the webparts installed, you can configure them to achieve dynamic filtering based on the page properties.

    Steps to Configure:
    1. Edit the Page where you want to add the web part.
    2. Add the PnP Search Webpart to your page:
      • Click on the + icon to add a web part.
      • Search for "PnP" and select the appropriate search webpart (e.g., “PnP Search Results”, “PnP Search Box”, etc.).
    3. Configure the Webpart:
      • Click on the webpart to edit its properties.
      • In the Search query settings, you can now build a dynamic query.
      • Use the {{Page.<PropertyName>}} token to substitute page properties dynamically in your KQL query.
        • For example, assuming you want to filter by the page filename, you could use: filename:"{{Page.FileLeafRef}}".
    4. Link the Search Box (if needed):
      • If you are using a PnP Search Box web part, configure it to pass the query to the PnP Search Results web part.
    5. Configure Results Layout:
      • Customize how the search results should be displayed according to your needs.
    6. Save your Changes: Once you’ve configured the webparts, save your page.

    3. Verify Dynamic Filtering

    To ensure everything is working correctly:

    1. Navigate to a different page with different properties.
    2. Verify that the search results change dynamically based on the current page’s properties.

    Additional Tips:

    • Debugging: If your query is not returning the expected results, double-check the property names and ensure they match exactly with the metadata on the pages.
    • Documentation & Samples: Refer to the PnP Modern Search documentation for more examples and detailed configuration options.

    Using PnP Modern Search Webparts provides a flexible and robust solution that empowers you to build complex search experiences tailored to your needs with dynamic data.

    I hope this information helps. Please do let us know if you have any further queries.

    Kindly consider accepting the answer if the information provided is helpful. This can assist other community members in resolving similar issues.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.