Changing The Format/Output Of Search Results

Modifying the output of your knowledge base's search results is quite straightforward with Helpjuice. The way our search works, is, in our questions.js file, every keystroke + 300ms of nothing happening triggers an ajax call to /search. With the Query being passed as a GET parameter.

Helpjuice returns search results in a JSON format, and our questions.js file already parses that, with the javascript function "show_results" rendering the results and inserting them into the dom. Here's how we can change the output of search results;

1. Open Main layout page

Inside Dashboard click Customize, and then Main Layout, on your left.

2. Replace {{ content_for_header }} with {{ javascript_includes }}

Find the line of code stated {{ content_for_header }}, and replace it with {{ javascript_includes }}. That's right, delete {{ content_for_header }} and insert {{ javascript_includes }}.

3. Over-ride the show_results function

Third and last step is to go to the bottom of the Main Layout page and find the following lines of code, right before the end of the tag:

function show_results() {
/* this is the function that's called every time Helpjuice renders search results */

If you'd like a sample of how the show_results function looks like, and how to show various items (such as breadcrumbs), take a look at our sample show_results code.

After changing the show_results function in the Main Layout, every other page is instantly affected, from a search-results stand point, as they all use main-layout as the default layout when rendering.

Please note, if you're stuck, or need any kind of help with customizing your Helpjuice account, feel free to contact us. We will be more than happy to assist you and do apply these changes for you.

Was this article helpful?