TQ
dev.com

Blog about software development

Subscribe

Precompile Handlebars Online

18 Apr 2016 - by 'Maurits van der Schee'

I have been playing around with Handlebars and it is awesome! It is a fast JavaScript implementation of the Mustache templating language. Handlebars allows you to precompile your template into a JavaScript object that you can store in a variable and use as a function to transform JSON into HTML. I was missing an online tool to test this out, so I decided to post it here. I've put in some sample data to play with.

Precompile Handlebars Online

Enter your template in the "input" field and press the "precompile" button. The result can be stored in a "var template = Handlebars.template(<insert output here>);" way and be executed by calling it as a function with the JSON data as an argument. You simply execute "var html = template(<insert json data here>);" to generate the HTML.

Template:

Precompiled:

Execute Handlebars Online

Enter your valid JSON data in the "data" field and press the "execute" button. The generated HTML will appear in the "rendered" field.

Data:

Rendered:

Compiled Handlebars templates are much faster than non-compiled templates as compiling is a very expensive part of templating.

NB: Normally precompilation is done using "nodejs" and the "handlebars" node package as you can read in the Handlebars documentation.