Dynamically Changing Content Search/Search Results WebPart's Query template







This is going to be a rather a small post, on how to change the query template for the content search webpart and Search results dynamically through javascript.












The above code is more self explanatory, this approach works for both Content Search and Search Results WebPart. You can use like below to identify whether its a Content Search or Search Results WebPart
if (this.displays[0] instanceof Srch.ContentBySearch)
if (this.displays[0] instanceof Srch.Result)

Download the complete code snippet!

You can download the complete code from above link, which I have used here. Add it to the Content Editor/Script Editor WebPart.

Happy coding! Peace!!

Comments