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 arrays using Handlebars

Displaying a list of objects is the most common reason we need a separate template language, otherwise we could easily get by with direct DOM manipulation. Handlebars has an easy, clean, and straightforward syntax for array iteration—the each construct, which works very similarly to the for each loops in other languages.

In this recipe, we're going to render a list of message objects. Each message object will have an author, arrival time, body, and read status. We're going to use a different style to distinguish between read and unread messages.

As usual in this chapter, the template will be included in the HTML file inside a script tag. However, the compilation can be called on any string that we choose; it is ...

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