O'Reilly logo

HTML5 Data and Services Cookbook by Mite Mitreski, Gorgi Kosev

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Rendering objects using Handlebars

Handlebars is a template language that adds minimal syntax to HTML. Its goal is to minimize the amount of logic present in the template and force the passed model object to correspond to what should be rendered in the view.

In this recipe, we will demonstrate some of the advantages and shortcomings of Handlebars using a simple example. We're going to render a user greeting based on the time of the day.

Getting ready

We need to download Handlebars from https://github.com/wycats/handlebars.js. The browser version is in the dist directory. Create a directory for the example and copy handlebars.js to this directory, or download directly (on Linux):

wget https://raw.github.com/wycats/handlebars.js/master/dist/handlebars.js ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required