Since SharePoint 2013 introduced the display templates, branding elements has been made a lot easier. Like for instance when you want to brand the search box on your site.
In the previous versions you mostly started the job by overriding the standard CSS of SharePoint. This approach will still work, but there is now an easier way. You now have the possibility to modify the search box template or create one of your own.
Important: The only downside at the moment (I hope this will change in the future) is that it involves to replace the OOTB small search box (check out this blog post).
On the default search boxes the property ServerInitialRender is set to true. When this property is set to true, the HTML markup is rendered from the assembly code instead of using the display template.
The search box templates that are being used are located in the master page gallery:
It contains the following two search box templates:
- Control_SearchBox.js and Control_SearchBox.html > this is the template for the search that is used on the search centers;
- Control_SearchBox_Compact.js and Control_SearchBox_Compact.html > this is the template for the small search box on each site.
Customizing the search box
I will explain you how to change the default search box image.
- Replace the default search box (follow this blog post), and remove or set the ServerInitialRender property to false;
- If you referenced another template than the Control_SearchBox_Compact.js one. Create the HTML template by copy and paste the Control_SearchBox_Compact.html file in the master page gallery (catalogs/masterpage/Display Templates/Search);
- Open the master page library in explorer view;
- Open the Search Box HTML template file;
- Search for the following text: var imagesUrl = GetThemedImageUrl(‘searchresultui.png’);
- Replace GetThemedImageUrl(‘searchresultui.png’) with "/_layouts/15/images/searchserver.ico";
- Search for the following class ms-srch-sb-searchImg, and remove it;
- Save the file and check refresh the site;
The results should look like this:
As you can see with this new template functionality possibilities are endless. Making customizations is easier, but it involves replacing the default search box. Once you replaced the default search box you have full control and you can make up your own HTML markup.