Changelog

JavaScript Icon changelog.com

handlebars.js: Optimized JavaScript templating based on Mustache.js

logged by @logbot 2010-09-12T20:09:00Z permalink #javascript

If you’ve ever used Jan Lehnardt’s Mustache.js, a port of Chris Wanstrath’s logic-less views project Mustache, be sure and checkout Handlebars.js from Yehuda Katz. Handlebars builds on Mustaches’ namesake {{mustaches}} data binding syntax by adding support for path-based expressions, block helpers, and optimized partial support.

Paths

Binding deep hashes with Mustache can be cumbersome. Yehuda’s new path-based expressions let you specify XPath-style expressions to bind to values deep within a nested data structure. Given the following data:

var data = {"person": { "name": "Alan" }, company: {"name": "Rad, Inc." } };

you could bind to company name with an expression like:

{{#person}}{{../company/name}}{{/person}}

[Source on GitHub] [Yehuda’s blog ppst]

0:00 / 0:00