tpl-js 是一个轻量的(仅1kb)、极速的 javascript 模板引擎。支持预编译,支持嵌入原生javascript语法,忽略不存在的变量,可直接在AMD、CMD以及全局环境中使用。
使用方法:
1.引入tpl.js
<scripttype="text/javascript"src="path/to/tpl.js"></script>或者在Sea.js和Node.js中:
vartpl=require('path/to/tpl');2.HTML模板
<divid="view"></div><scripttype="text/template"id="demo"><p>Hi,I'm<%=author%><%=aythig%></p><p>Icawrite:<%for(vari=0;i<laguages.legth;i++){echo((i===0?"":",")+laguages[i]);}%></p></script>3.执行渲染
cosole.log(tpl('#demo',{author:"Joy",laguages:["javascript","php","shell"]}));结果为:
<p>Hi,I'mJoy</p><p>Icawrite:javascript,php,shell</p>
在线例子:https://iceue.github.io/tpl.js/
在线文档:https://github.com/iceue/tpl.js







评论