您的位置:首页 > 其它

myTemplate模板引擎

2014-05-30 18:22 447 查看
# myTemplate-0.2.0 简洁的 javascript 模板引擎 [https://github.com/guoyao/myTemplate](https://github.com/guoyao/myTemplate) ## 特性 1. 源码简洁明了 2. 不使用with,因此模板中可以输出全局变量 3. 支持Node RequireJS 4. 支持所有流行的浏览器 ## 快速上手 ### 编写模板 使用一个``type="text/template"``的``script``标签存放模板:

Name:

Age:

Gender:

Children:

  • Name:
  • Age:
  • Gender:
### 渲染模板 var data = { name: 'guoyao', age: 26, gender: 'male', children: [ { name: 'child 1', age: 5, gender: 'female' }, { name: 'child 2', age: 3, gender: 'male' } ] }; var template = document.getElementById('template').innerHTML; var html = myTemplate(template, data); document.getElementById('content').innerHTML = html; [演示](http://demo.guoyao.me/myTemplate/demo/) ## 模板语法 <%if (this.age > 25){%> <%for (var i=0;i <%=i%>. <%=this.children[i].name%> <%}%> <%}%> ## 下载 * [myTemplate.js](https://raw.github.com/guoyao/myTemplate/master/dist/myTemplate.js) *(未压缩版, 2.38 kb)* * [myTemplate.min.js](https://raw.github.com/guoyao/myTemplate/master/dist/myTemplate.min.js) *(压缩版, 767 b)* * Install with [Bower](http://bower.io): `bower install myTemplate`. ## 方法 ### myTemplate(template, data) 如果没有 data 参数,那么将返回一渲染函数,否则直接返回渲染结果。 ## 开发者 **Guoyao Wu** + [http://guoyao.me](http://guoyao.me) + [http://github.com/guoyao](http://github.com/guoyao) + [https://twitter.com/wuguoyao](https://twitter.com/wuguoyao) ## 授权协议 Released under the BSD License ============ © guoyao.me
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  template 模板引擎