Customizing the Search Control Display Template

I have customers who often want a custom search page of some sort, so I end up customizing the Search Control Display Template and making a minor query change. This most is more for my reference, but I figured these two simple things may help others.

When you create a custom page and drop search Web Parts (Search Box, Search Result, perhaps Refinement), a user will navigate to the page and a bunch of default results show up. The fix for this is easy… Simply edit your Search Query.


Replace {searchboxquery} with \\{searchboxquery}. No results will appear. EDIT: SharePoint MVP Mikael Svenson said it would be best to use {?{searchboxquery}} instead of \\{searchboxquery} – do that instead! Note that the opening and closing brackets should surround the entire query, for example {?{searchboxquery} Path:}.


Unfortunately, you’ll now see the “Nothing here matches your search” message when you navigate to the page. To fix that, using SharePoint Designer, navigate to the Search Display Templates under All Files -> _catalogs -> masterpage -> Display Templates -> Search. I often will make a copy of the Control_SearchResults.html file as I don’t want to make changes to it to prevent impacting search results across the entire site. Give the copied file an appropriate name. Edit the file and change the value in the attribute to distinguish this Display Template from the default Display Template (the title value is used as the display name in the Control Display Template drop down list).

Search for the text:


Simply change it to:

var currentQueryTerm = ctx.DataProvider.get_currentQueryState().k; if(ctx.ClientControl.get_shouldShowNoResultMessage() && currentQueryTerm!=""){

Save the file. On SharePoint, edit the Search Results Web Part and change the Results Control Display Template to your new custom Control Display Template. When the user now navigates to the page, the ‘no results’ message is no longer displayed, until they search for a term that indeed has no results!

Trevor Seward is a Microsoft Office Apps and Services MVP who specializes in SharePoint Server administration, hybrid scenarios, and SharePoint Online. He has been working with SharePoint for 16 years from SharePoint 2003 on up, managing environments with terabytes of content for 150,000+ user organizations. Trevor is an author of Deploying SharePoint 2016 and Deploying SharePoint 2019. You can find him on Twitter and in /r/sharepoint.