SP2013 - Changing the default group template in Search Results WP (GroupTemplateId)
Hi Search Enthusiasts
I came across the need to change the default group template, for a specific Search Result Web Part.
I have configured my search center with the default layout -all in one column-. Upon certain Query rules, I may encounter results including Best Bets, Result Blocks and Core Results. All those are considered groups in the rendering of the Search Result Web Part although I wanted to have more controls about their rendering (upon certain criteria, I would like to display or not Result Blocks and Core Results for instance).
Overall how the Search Results WP is rendered ?
The Search Result Web Part Display Templates -Control_SearchResults.html- shows the groups rendering invocation.
<div id="Groups" class="ms-srch-result-groups">
ctx.ListDataJSONGroupsKey = "ResultTables";
_#= ctx.RenderGroups(ctx) =#_
Each group is rendered with the same default template called Group_Default.html. Within each group, each Result Item is rendered based on its type (see Search Display Templates Item_*).
The WP Properties UI only allow you to change the Control Display (WP-level) and Result Item template (Result-Item Level). The Group Template is not configurable through the UI.
The Group template shows the call to render the result items within a group.
<div id="_#= $htmlEncode(id + Srch.U.Ids.groupContent) =#_" class="ms-srch-group-content">_#= ctx.RenderItems(ctx) =#_<div class="ms-srch-group-clear"></div></div>
To change that Group template the solution is to export the Search Result WP, change the attribute GroupTemplateId (blank by default) to point to your new Group template.
<property name="GroupTemplateId" type="string">~sitecollection/_catalogs/masterpage/Display Templates/Search/Group_Default_RightWP.js</property>
Once changed, import your new Search Result WP.
You can now use a different look and feel or other customization you may require.