文章分类 -  JS_Handlebars

摘要:Handlebars为应用和helpers提供一系列的APIs和有效的方法。8.1 基础1. Handlebars.compile(template, options)编译一个模板以使其可以马上运行。 var template = Handlebars.compile('{{foo}}'); t... 阅读全文
posted @ 2014-12-19 15:24 South Wind 阅读(1103) 评论(0) 推荐(0)
摘要:Handlebars提供一系列内置helpers,像if条件从句和each迭代器。7.1 if helper可以使用if helper有条件的呈现一个代码块。如果参数返回false、undefined、null、""或者[](一个返回false的值),Handlebars将不会呈现代码块。 ... 阅读全文
posted @ 2014-12-18 18:59 South Wind 阅读(587) 评论(0) 推荐(0)
摘要:在Handlebars模板中,helpers可以使用任何上下文。可以使用Handlebars.registerHelper方法注册一个helper。 By {{fullName author}} {{body}} Comments {{#each comments}} ... 阅读全文
posted @ 2014-12-18 17:35 South Wind 阅读(167) 评论(0) 推荐(0)
摘要:可以再Handlebars代码中使用注释。 {{!-- only output this author names if an author exists --}} {{#if author}} {{firstName}} {{lastName}} {{/if}} ... 阅读全文
posted @ 2014-12-18 17:24 South Wind 阅读(768) 评论(0) 推荐(0)
摘要:1. 简单路径Handlebars支持简单路径,就像Mustache: {{name}}2. 嵌套路径Handlebars也支持嵌套的路径,使得可以查询嵌套的属性在当前的上下文中。 {{title}} By {{author.name}} {{body}} ... 阅读全文
posted @ 2014-12-18 17:20 South Wind 阅读(157) 评论(0) 推荐(0)
摘要:块表达式允许你定义helpers,该helpers调用一个有着与当前不同上下文的模板块。让我们看一下下面的helpers,它将会获得一个HTML列表: {{#list people}} {{firstName}} {{lastName}} {{/list}}如果有上下文: { ... 阅读全文
posted @ 2014-12-18 17:15 South Wind 阅读(112) 评论(0) 推荐(0)
摘要:Handlebars中通过{{expression}}返回HTML转义值。如果你不想Handlebars转义(不是解析,三个大括号中的变量依旧会被解释)一个值,可以使用三个大括号:{{{ {{title}} {{{body}}} 相应上下文: { tit... 阅读全文
posted @ 2014-12-18 17:04 South Wind 阅读(570) 评论(0) 推荐(0)
摘要:Handlebars让我们可以更加高效地创建语义化的模板(semantic templates)。Handlebars可以与Mustache templates近乎完美的兼容。大多数情况下,你可以通过使用Handlebars替换(swap out)Mustache从而继续使用自己当前的模板(即,可以... 阅读全文
posted @ 2014-12-13 17:08 South Wind 阅读(377) 评论(0) 推荐(0)