JavaScript Templates - Example

We'll focus on using the Handlebars template library.  Other template systems will do similar things though, with different syntax.

With Handlebars, the key parts are:

Handlebars syntax are based on double curly braces, like {{ handlebar expression }}

So to iterate through the <code>seasons</code> array, our Handlebars template would look like:

<ul>
  {{#seasons}}
  <li>{{.}}</li>
  {{/seasons}}
</ul>

To re-implement our "seasons list" example using Handlebars, we could something like:  

See the working examples:

Copyright © David Heitmeyer