1.0.2 • Published 9 years ago

node-ts-tmpl v1.0.2

Weekly downloads
6
License
MIT
Repository
github
Last release
9 years ago

tmpl

a tiny&simple template engine with ES6 DNA

Build Status Coverage Status

installation

via NPM:

Please use tmpl by io.js(v2.1.0)

npm isntall node-ts-tmpl --save

Basic Usage

assume that you have an object with the structure like:

{
  username: 'DavidCai',
  isLogin: true,
  lists: [1, 2, 3]
}

variables

<p>hello,{%=username%}</p>
<!--out put:-->
<p>hello,DavidCai</p>

unescaped text

tmpl will escape all text you put in {%=...%}, unless you put them in {%!...%}

{%!<p>unescaped</p>%}
<!--out put:-->
<p>unescaped</p>

if statement

{% if login %}
<p>has login!</p>
{% endif %}
<!--out put:-->
<p>has login!</p>

for loop

{% for value in lists%}
<span>{%value%}</span>
{% endfor %}
<!--out put:-->
<span>1</span>
<span>2</span>
<span>3</span>

API

render(tmpl_html, obj) String

options:

  • tmpl_html: html file with the tmpl statement
  • obj: object to fill the tmpl statement