-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
HTML5 Data and Services Cookbook
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.
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
Let's write the code:
Create index.html containing a name input, a greeting placeholder, and the Handlebars template:
<!DOCTYPE HTML> <html> <head> <title>Displaying objects with Handlebars</title> <...
Change the font size
Change margin width
Change background colour