Handlebars.js は、テンプレート内に過剰なロジックを持ち込まず、セマンティックでクリーンな HTML を生成する Mustache 拡張テンプレートエンジンです。
基本表現と組み込みブロックヘルパー
<p>{{firstname}} {{lastname}}</p>
<p>{{{rawHtmlContent}}}</p>
{{#if isActive}}
<span class="active">Active</span>
{{else}}
<span class="inactive">Inactive</span>
{{/if}}
{{#each items}}
<li>{{this}}</li>
{{/each}}
{{#with author}}
<h2>By {{name}}</h2>
{{/with}}
カスタムヘルパー(Custom Helpers)
Handlebars.registerHelper('fullName', function (person) {
return person.firstName + ' ' + person.lastName;
});
<p>{{fullName user}}</p>