Buy Handlebars swag on DevSwag!

传入数据,执行 Handlebars 返回 渲染后的 HTML。

var source   = $("#entry-template").html();
var template = Handlebars.compile(source);

var context = {title: "My New Post", body: "This is my first post!"}
var html    = template(context);

渲染结果

<div class="entry">
  <h1>My New Post</h1>
  <div class="body">
    This is my first post!
  </div>
</div>

示例

选项

这里的 template() 允许传入第二个参数作为选项

The template function can be passed an options object as the second parameter which allows for customization:

发现翻译错误?告诉我们。
Fork me on GitHub