首页 > 其他 > 详细

Handlebars 介绍

时间:2015-10-01 17:59:46      阅读:212      评论:0      收藏:0      [点我收藏+]

最新项目用到了Ember.js前端框架,第一次使用这样的框架,准备国庆节花2天时间,研究一下它的用法。

Ember框架的模板引擎用到了handlebars, 先看国外的一篇介绍文章:An Introduction to Handlebars

手动写了一个测试示例:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <script id="blogs" type="text/x-Handlebars-template1">
       <div class="entry">
      <h1>{{title}}</h1>
      <div class="body">
        {{body}}
      </div>
    </div>
    </script>
    <div id="temp"></div>
</body>
</html>
<script src="scripts/handlebars-v4.0.2.js"></script>
<script type="text/javascript">
    var context = {
        title: "handlebars introduction",
        body: "handlebar is js template..."
    };
    var template = Handlebars.compile(document.getElementById("blogs").innerHTML);
    document.getElementById("temp").innerHTML = template(context);
</script>

 

Handlebars 介绍

原文:http://www.cnblogs.com/andrewcn/p/4851148.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!