t.js - 一个微型javascript模板框架
openkk
12年前
T.js 是一个微型的 JavaScript 模板引擎,压缩后大小只有 400 个字节。
Features
- Simple interpolation:
{{=value}}
- Scrubbed interpolation:
{{%unsafe_value}}
- Name-spaced variables:
{{=User.address.city}}
- If/else blocks:
{{value}} <<markup>> {{:value}} <<alternate markup>> {{/value}}
- If not blocks:
{{!value}} <<markup>> {{/value}}
- Object/Array iteration:
{{@object_value}} {{=_key}}:{{=_val}} {{/@object_value}}
- Multi-line templates (no removal of newlines required to render)
- Render the same template multiple times with different data
- Works in all modern browsers
用法:
var template = new t("<div>Hello {{=name}}</div>"); document.body.innerHtml = template.render({name: "World!"});