The contrib module, velocity
, nicknamed
Solritas, is a simple template engine that lets you build user interfaces directly in Solr using
Apache Velocity, a very simple macro language to generate the HTML. It's similar to JSP or PHP, but with a simpler syntax consisting of just a handful of commands. It is very simple to pick up, as you can see in the following snippet of code, for rendering the HTML that displays the ID and name of an artist pulled from the first Solr document in a list of results:
#set($doc = $response.results.get(0)) #set($id = $doc.getFieldValue("id")) <div>ID: $id</div> <div>Name: #field('a_name')</div>
When a Velocity template is invoked, Solritas places some objects, indicated with a $
character, into a rendering context that you can use, such as $response
and $request
. In the preceding example, you can see that the first result in the response is assigned to the $doc
object variable using the #set
command...