Skip to content

Instantly share code, notes, and snippets.

@wcc526
Created September 26, 2015 12:09
Show Gist options
  • Save wcc526/ce5c30b8489c31174106 to your computer and use it in GitHub Desktop.
Save wcc526/ce5c30b8489c31174106 to your computer and use it in GitHub Desktop.
nodejs

Handlebars.js

参考自ghostchina

value

<div class="demo">
<h1>{{name}}</h1>
<p>{{content.title}}</p>
</div>

block

{
programme: [
{language: "JavaScript"},
{language: "HTML"},
{language: "CSS"}
]
}
<ul>
{{#programme}}
<li>{{language}}</li>
{{/programme}}
</ul>

each block helper

{
name: ["html","css","javascript"]
};
<ul>
{{#each name}}
<li>{{this}}</li>
{{/each}}
</ul>

if else

如果false,undefined, null, "" 或者 [] 不会执行

{{#if list}}
<ul id="list">
{{#each list}}
<li>{{this}}</li>
{{/each}}
</ul>
{{else}}
<p>{{error}}</p>
{{/if}}

unless

这个与if语句相反

with block

<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 }}

Path

{
"person":
{ "name": "Alan" },
company:
{"name": "Rad, Inc." }
};
{{#with person}}
<h1>{{../company.name}}</h1>
{{/with}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment