参考自ghostchina
<div class="demo">
<h1>{{name}}</h1>
<p>{{content.title}}</p>
</div>
{
programme: [
{language: "JavaScript"},
{language: "HTML"},
{language: "CSS"}
]
}
<ul>
{{#programme}}
<li>{{language}}</li>
{{/programme}}
</ul>
{
name: ["html","css","javascript"]
};
<ul>
{{#each name}}
<li>{{this}}</li>
{{/each}}
</ul>
如果false,undefined, null, "" 或者 [] 不会执行
{{#if list}}
<ul id="list">
{{#each list}}
<li>{{this}}</li>
{{/each}}
</ul>
{{else}}
<p>{{error}}</p>
{{/if}}
这个与if
语句相反
<div class="entry">
<h1>{{title}}</h1>
{{#with author}}
<h2>By {{firstName}} {{lastName}}</h2>
{{/with}}
</div>
{
title: "My first post!",
author: {
firstName: "Charles",
lastName: "Jolley"
}
}
{{! handlebars comments }}
{
"person":
{ "name": "Alan" },
company:
{"name": "Rad, Inc." }
};
{{#with person}}
<h1>{{../company.name}}</h1>
{{/with}}