SharePoint Online / Office 365 : Steps for Adding Search Result Webpart in Pagelayout


Recently, while working on a SharePoint online project I faced the requirement to add the Configured Search result webpart in PageLayout. Which should show the result based on the one of other taxonomy field on the page.

Steps to include the Search Result Webpart in Pagelayout:

1.Create one page and configure the Search Result Webpart there. (Tip: Create the separate result source, so no dependency on changing the query later in pagelayout if any modification.)

2. Export the webpart, open the exported file in any editor. Which will look something like below image. We will require all these property value to configure the webpart in layout.


3.  Create the page layout and set up the basic design.
4.  Register the following assembly at the top of your Pagelayout.
<%@ Register Tagprefix="SearchWebControls" Namespace="Microsoft.Office.Server.Search.WebControls" Assembly="Microsoft.Office.Server.Search, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
 5. Now find the desire <ZoneTemplate>  where there is requirement to add the search webpart and add the following piece of code inside that. change the property value from the export file of configured search result webpart.

<SearchWebControls:ResultScriptWebPart runat="server" DataProviderJSON=" {'QueryGroupName':'Default','QueryPropertiesTemplateUrl':'sitesearch://webroot <Copy the property value from exported webpart>}" BypassResultTypes="<Copy the property value from exported webpart>" ItemTemplateId="<Copy the property value from exported webpart>" ItemBodyTemplateId="<Copy the property value from exported webpart>" ResultTypeId="<Copy the property value from exported webpart>" SelectedPropertiesJson="<Copy the property value from exported webpart>" HitHighlightedPropertiesJson="<Copy the property value from exported webpart>" AvailableSortsJson="<Copy the property value from exported webpart>" ShowLanguageOptions="<Copy the property value from exported webpart>" ShowPaging="<Copy the property value from exported webpart>" ShowBestBets="<Copy the property value from exported webpart>" ShowPersonalFavorites="<Copy the property value from exported webpart>" ShowDidYouMean="<Copy the property value from exported webpart>" ShowAdvancedLink="<Copy the property value from exported webpart>" ShowPreferencesLink="<Copy the property value from exported webpart>" ShowResultCount="<Copy the property value from exported webpart>" ShowResults="<Copy the property value from exported webpart>" PreloadedItemTemplateIdsJson="<Copy the property value from exported webpart>" ShowAlertMe="<Copy the property value from exported webpart>" QueryGroupName="<Copy the property value from exported webpart>" RenderTemplateId="<Copy the property value from exported webpart>" StatesJson="{}" ServerIncludeScriptsJson="" Title="Tools" Description="Displays the search results and the properties associated with them." AllowRemove="" AllowZoneChange="True" AllowMinimize="False" AllowConnect="True" AllowEdit="False" AllowHide="True" ChromeType="TitleOnly" ChromeState="Normal" HelpMode="Modeless" WebPart="true" ></SearchWebControls:ResultScriptWebPart>

You can add the other properties value like above from the exported webpart.

6. Save and publish the pagelayout. based on your result source/query it will start showing the result when you create new page using this pagelayout.


Happy Coding!

Comments

  1. Thanks for your post. Unfortunately doesn't work for me. SP just seems to ignore the web part.

    ReplyDelete
  2. This article provides clear steps for adding a search result web part in SharePoint Online—very helpful for enhancing site functionality! If you're also a gamer, Skynode is a fantastic tool to help you manage your game library while you optimize your SharePoint skills.

    ReplyDelete

Post a Comment

Popular posts from this blog

Search Result Webpart,Filter result If QueryString is present in URL

SharePoint 2013 Workflow gets canceled automatically

Permission denied for "Add and Customize Pages" in Sharepoint Online