Add search web part to page layout

Today I tried to add a search result web part to a page layout. Initially I thought to do this the same way as I would with an content editor web part.

So first the steps on how I would add a content editor web part to my page layout.

I find the following section in my page layout:

<WebPartPages:WebPartZone runat=”server” Title=”My zone” ID=”MyZone”><ZoneTemplate>

</ZoneTemplate></WebPartPages:WebPartZone>

 

then within the zone I add within the ZoneTemplate a bit of web part code:

<WebPartPages:ContentEditorWebPart runat=”server” __MarkupType=”xmlmarkup” WebPart=”true” __WebPartId=”{359811A8-E5ED-4B67-821A-56D65725FDBC}” >

WebPart xmlns:xsd=”http://www.w3.org/2001/XMLSchema&#8221; xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221; xmlns=”http://schemas.microsoft.com/WebPart/v2″&gt;

<Title>My web part</Title>

<FrameType>None</FrameType>

<Description>Allows authors to enter rich text content.</Description>

<IsIncluded>true</IsIncluded>

<ID>g_59d8779b_5895_4724_9c3e_62db1dd58558</ID>

<ContentLink xmlns=”http://schemas.microsoft.com/WebPart/v2/ContentEditor&#8221; />

<Content xmlns=”http://schemas.microsoft.com/WebPart/v2/ContentEditor”>&lt;![CDATA[&nbsp;]]></Content>

<PartStorage xmlns=”http://schemas.microsoft.com/WebPart/v2/ContentEditor&#8221; />

</WebPart>

</WebPartPages:ContentEditorWebPart>

 

In the above the <WebPart> … </WebPart> xml is the same as when you export a web part on a SharePoint page.

Now the same with my search web part. I’m quite quickly getting errors when I tried to create pages with my page layout. As I’m working with office 365 the ULS logs are not accessible and a correlation id is less than no use to me.

My Solution

Back to added a search result web part. First of all I had to find out where the Search result web part comes form. When I exported the web part the name of the search results web part looked like ResultScriptWebPart. So I looked that up using Bing and I got to the article giving me the dll name.

Then I added the following line near the top of my page layout:

<%@ Register Tagprefix=”SearchWebControls” Namespace=”Microsoft.Office.Server.Search.WebControls” Assembly=”Microsoft.Office.Server.Search, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>

Then I found the <ZoneTemplate> that I wanted to add my search web part to:

<WebPartPages:WebPartZone runat=”server” Title=”Left” ID=”Left”>

<ZoneTemplate>

<SearchWebControls:ResultScriptWebPart runat=”server”

DataProviderJSON=”{&quot;QueryGroupName&quot;:&quot;Default&quot;,&quot;QueryPropertiesTemplateUrl&quot;:&quot;querygroup://webroot/Pages/Dummysearch.aspx?groupname=Default&quot;,&quot;IgnoreQueryPropertiesTemplateUrl&quot;:false,&quot;SourceID&quot;:&quot;5ce35ddf-d563-4d32-b850-c45760c9a3bf&quot;,&quot;SourceName&quot;:&quot;Product Catalog&quot;,&quot;SourceLevel&quot;:&quot;Ssa&quot;,&quot;CollapseSpecification&quot;:&quot;&quot;,&quot;QueryTemplate&quot;:&quot;{searchboxquery}&quot;,&quot;FallbackSort&quot;:null,&quot;FallbackSortJson&quot;:&quot;null&quot;,&quot;RankRules&quot;:null,&quot;RankRulesJson&quot;:&quot;null&quot;,&quot;AsynchronousResultRetrieval&quot;:false,&quot;SendContentBeforeQuery&quot;:true,&quot;BatchClientQuery&quot;:true,&quot;FallbackLanguage&quot;:-1,&quot;FallbackRankingModelID&quot;:&quot;&quot;,&quot;EnableStemming&quot;:true,&quot;EnablePhonetic&quot;:false,&quot;EnableNicknames&quot;:false,&quot;EnableInterleaving&quot;:true,&quot;EnableQueryRules&quot;:true,&quot;EnableOrderingHitHighlightedProperty&quot;:false,&quot;HitHighlightedMultivaluePropertyLimit&quot;:-1,&quot;IgnoreContextualScope&quot;:false,&quot;ScopeResultsToCurrentSite&quot;:false,&quot;TrimDuplicates&quot;:true,&quot;Properties&quot;:{},&quot;PropertiesJson&quot;:&quot;{}&quot;,&quot;ClientType&quot;:&quot;&quot;,&quot;UpdateAjaxNavigate&quot;:true,&quot;SummaryLength&quot;:180,&quot;DesiredSnippetLength&quot;:90,&quot;PersonalizedQuery&quot;:false,&quot;FallbackRefinementFilters&quot;:null,&quot;IgnoreStaleServerQuery&quot;:false,&quot;RenderTemplateId&quot;:&quot;DefaultDataProvider&quot;,&quot;AlternateErrorMessage&quot;:null,&quot;Title&quot;:&quot;&quot;}”

BypassResultTypes=”True”

ItemTemplateId=”~sitecollection/_catalogs/masterpage/Display Templates/Search/_Item_Product.js”

ItemBodyTemplateId=”~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_CommonItem_Body.js”

ResultTypeId=””

SelectedPropertiesJson=”[&quot;Title&quot;,&quot;Path&quot;,&quot;Description&quot;,&quot;EditorOWSUSER&quot;,&quot;LastModifiedTime&quot;,&quot;CollapsingStatus&quot;,&quot;DocId&quot;,&quot;HitHighlightedSummary&quot;,&quot;HitHighlightedProperties&quot;,&quot;FileExtension&quot;,&quot;ViewsLifeTime&quot;,&quot;ParentLink&quot;,&quot;FileType&quot;,&quot;IsContainer&quot;,&quot;SecondaryFileExtension&quot;,&quot;DisplayAuthor&quot;]”

HitHighlightedPropertiesJson=”[&quot;Title&quot;,&quot;Path&quot;,&quot;Author&quot;,&quot;SectionNames&quot;,&quot;SiteDescription&quot;]”

AvailableSortsJson=”[{&quot;name&quot;:&quot;Relevance&quot;,&quot;sorts&quot;:[]},{&quot;name&quot;:&quot;Date(Newest)&quot;,&quot;sorts&quot;:[{&quot;p&quot;:&quot;Write&quot;,&quot;d&quot;:1}]},{&quot;name&quot;:&quot;Date(Oldest)&quot;,&quot;sorts&quot;:[{&quot;p&quot;:&quot;Write&quot;,&quot;d&quot;:0}]},{&quot;name&quot;:&quot;Lifetime Views&quot;,&quot;sorts&quot;:[{&quot;p&quot;:&quot;ViewsLifeTime&quot;,&quot;d&quot;:1}]},{&quot;name&quot;:&quot;Recent Views&quot;,&quot;sorts&quot;:[{&quot;p&quot;:&quot;ViewsRecent&quot;,&quot;d&quot;:1}]}]”

ShowLanguageOptions=”False”

ShowPaging=”False”

ShowBestBets=”False”

ShowPersonalFavorites=”False”

ShowDidYouMean=”False”

ShowAdvancedLink=”False”

ShowPreferencesLink=”False”

ShowResultCount=”False”

PreloadedItemTemplateIdsJson=”[&quot;~sitecollection/_catalogs/masterpage/Display Templates/Search/Group_Default.js&quot;,&quot;~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_Default.js&quot;,&quot;~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_Site.js&quot;,&quot;~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_Word.js&quot;,&quot;~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_PowerPoint.js&quot;,&quot;~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_Person_CompactHorizontal.js&quot;,&quot;~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_BestBet.js&quot;,&quot;~sitecollection/_catalogs/masterpage/Display Templates/Search/Item_WebPage.js&quot;]”

ShowAlertMe=”False”

QueryGroupName=”Default”

RenderTemplateId=”~sitecollection/_catalogs/masterpage/Display Templates/Search/Control_SearchResults.js”

StatesJson=”{}”

ServerIncludeScriptsJson=”null”

Title=”Search Web part”

FrameType=”None”

SuppressWebPartChrome=”False”

Description=”Displays the search results and the properties associated with them.”

IsIncluded=”True”

ZoneID=”Left”

PartOrder=”1″

FrameState=”Normal”

AllowRemove=”True”

AllowZoneChange=”True”

AllowMinimize=”True”

AllowConnect=”True”

AllowEdit=”True”

AllowHide=”True”

IsVisible=”True”

DetailLink=””

HelpLink=””

HelpMode=”Modeless”

Dir=”Default”

PartImageSmall=””

MissingAssembly=”Cannot import this Web Part.”

PartImageLarge=””

IsIncludedFilter=””

ExportControlledProperties=”True”

ConnectionID=”00000000-0000-0000-0000-000000000000″

ID=”g_ad1f2313_25f2_25b2_1241_b87395278af1″

ChromeType=”None”

ExportMode=”All”

__MarkupType=”vsattributemarkup”

__WebPartId=”{AD1F2313_25F2_25B2_1241_B87395278AF1}”

WebPart=”true”

Height=””

Width=””>

</SearchWebControls:ResultScriptWebPart>

</ZoneTemplate></WebPartPages:WebPartZone>

Ok, there are many properties that can be set within this web part. The above is only a small selection.

 

By Pieter Veenstra

Business Applications and Office Apps & Services Microsoft MVP working as a Microsoft Productivity Principal Consultant at HybrIT Services. You can contact me using contact@veenstra.me.uk.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: