Quick Tip: Suppress the display of submitted search terms in a SharePoint 2013 search box web part

Author by Pete Hurth

The Problem: A search results page can accept the k= parameter in the URL which passes the query to a search box web part. Unfortunately this is sometimes not desired as the query can be a bit ugly.

One solution might be to use a= in the URL parameter. This suppresses the display; however it seems to also break the search results. So… not an ideal solution.

In previous versions of SharePoint you could simply check a box in the search box web part properties called "Display Submitted Search". See this blog for a description of how to fix this in previous versions of SharePoint: http://strandsofsharepoint.blogspot.com/2013/12/use-a-url-parameter-when-passing-hidden.html. This does not work in SharePoint 2013 since the option is no longer available in the web part (the search web parts have been completely redesigned to use display templates). To make this same change you must edit the control display template used by SharePoint to render the search box.

I'm assuming you have at least a passing familiarity with display templates. If not, see the following article for an overview on working with SharePoint display templates: http://msdn.microsoft.com/en-us/library/office/jj945138(v=office.15).aspx

Now that you know all there is to know about display templates… navigate to: /_catalogs/masterpage/Display Templates/Search/ and locate "Control_SearchBox.html". Do not edit the default display template. It's bad karma to do so. Instead make a copy of this file (not the .js file, just the html file). Rename it to something appropriate like "Control_SearchBox-nosub.html".

If using SharePoint Designer, right click on the file and choose Edit in Advanced Mode. The display template will open in a new tab. Now scroll down to the element (line 61 in the screen shot below).

Note the variable in the value= section:

"_#= $htmlEncode(ctx.ClientControl.get_currentTerm()) =#_"

Remove this text (everything between but not including the quotation marks). Save and close the file.

While you're editing the display template, be sure to change the title. If you don't, you won't be able to tell which display template is which in the web part properties.

Remember when editing display templates that generally your updates will not be visible to normal users until you publish your changes. Sadly, this can't be done from within SharePoint Designer. To do so, go to your site in SharePoint and visit Site Settings.

Last step: go to your search box web part properties, expand the Settings section and select your new display template from the drop down list.

Now when you are taken to your search results page you see a nice clean search box:

Author

Pete Hurth

Social Collaboration Solution Lead