Using Handlebars.js To Display Results From Solr- A Primer

Handlebars provides the power necessary to let you build semantic templates effectively with no frustration.

Handlebars.js is a really great way to render search results from Solr.

Handlebars.js has become the defacto standard for templating in JavaScript, filling the void left from the abandonment and non-replacement of the jQuery template project. Handlebars.js is an implementation of the mighty platform-independant mustache project

JavaScript templating makes it a lot easier to implement cool interface functionality on your search result page such as responsive design, autoscrolling and more. Handlebars make JS templating a cinch.

You get the benefit of Handlebars.js on webpages that have a lot of repeating code such as lists, search-results and libraries.

In order to see Solr and Handlebars.js in action click here or copy and paste the code below into an empty .html file.

Article written by

Fergus McDowall
Senior Consultant at Comperio. Dedicated emacs user.

3 response to: «Using Handlebars.js To Display Results From Solr- A Primer»

  1. July 26, 2013 at 17:42 | Permalink

    Hi Fergus,
    I tried your code, It’s not working.


  2. September 23, 2015 at 13:00 | Permalink

    hi Fergus, thanks for posting this. works great and is lightening fast. Am trying to work out how to integrate customised bias/weighting settings to be appended to the solr query in a multilingual environment….if you have had any experience of this, can you post an update if you have time?

    Also..I notice a few odd behavioural things, such as when you have facets applied and then type into the search box, it seems to reset the chosen facets. that a jquery issue or handlebars issue?

    anyway, thanks again for posting.


  3. September 28, 2015 at 11:10 | Permalink

    Hi Gus

    This code is now a few years old and is probably due for a revamp. Its quite possible that there is now some mismatch between versions of Solr/JS/moustache which make facets and filters not work as intended.

    For the relevancy stuff- the solr wiki is quite good:

    Ping me on twitter (@fergiemcdowall) if you need any more help :)


Leave a response

XHTML: These tags are allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">


Comperio AS
Øvre Slottsgate 27
NO-0157 Oslo,
+47 22 33 71 00
View map


Search Provider Sverige AB
Gamla Brogatan 34
SE-11 120 Stockholm
+46 8-21 49 00
View map