Handlebars模板 教程 Handlebars
{{ }} //不解析html标签而是直接显示出来
{{{ }}} //解析html标签
{{#if author}} //定义了author属性就输出以下
<h1>{{firstName}} {{lastName}}</h1>
{{/if}}
{{#if author}}
<h1>{{firstName}} {{lastName}}</h1>
{{else}}
<h1>Unknown Author</h1>
{{/if}}
{{#unless license}} //#unless 和 if 相反 ,条件为假时才执行
<h3 class=”warning”>WARNING: This entry does not have a license!</h3>
{{/unless}}
{{author.name}} {{author.id}}
author:{ name: “Yehuda Katz”,id:187}
{{#each people}}
<li>{{this}}</li>
{{/each}}
people:{ a:[‘a1′,’a2’],b:[‘b1′,’b2’] }
<li>a1,a2</li>
<li>b1,b2</li>
{{#each people}}
<li>{{this}}</li>
{{/each}}
people:[ [‘a1′,’a2’],[‘b1′,’b2’] ]
<li>a1,a2</li>
<li>b1,b2</li>
{{#each paragraphs}} //有定义paragraphs就遍历
<p>{{this}}</p>
{{else}} 没有就输出以下
<p class=”empty”>No content</p>
{{/each}}
paragraphs:[ [‘a1′,’a2’],[‘b1′,’b2’] ],
为遍历添加索引
{{#each array}}
{{@index}}: {{this}}
{{/each}}
为遍历获取键值对
{{#each object}}
{{@key}}: {{this}}
{{/each}}