Sdílet prostřednictvím


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. 

 

 

Stay Tuned.

Comments

  • Anonymous
    July 09, 2013
    Will Microsoft be posting complete reference documentation on the display template api? I mean, you are using the ctx and Srch objects, but I can't find any reference documentation on it. E.g. why one needs to set the ListDataJSONGroupsKey property to the value "ResultTables".

  • Anonymous
    July 28, 2013
    Hi Carl As far as I know, there is no plan to publish such documentation. The code snippet I referenced (i.e. "ListDataJSONGroupsKey") is originated from the default Control_SearchResults.html. It was meant to highlight how the groups are rendered within the SRWP. Existing resources around Search Display Templates : technet.microsoft.com/.../jj944947.aspx msdn.microsoft.com/.../jj191506.aspx msdn.microsoft.com/.../jj945138.aspx

  • Anonymous
    March 25, 2014
    If you created a Query rule, you could add a result block, expand Settings and you can specify the group display template url as well as the item display template url; These url's are pointers to js files generated from your custom display template files in html form.

  • Anonymous
    April 19, 2014
    @Louie : correct. At the result block level, you can control group and item templates.