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.

searchboxquerydefault

 

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:https://tenant.sharepoint.com/sites/projectSite}.

searchboxqueryfixed

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 <title> 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:

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!

 

One Comment

  1. Thanks for sharing . Its helpful.

Leave a Reply