dotpl-js - 纯javascript模板引擎


BSD
跨平台
JavaScript

软件简介

Dotpl-JS
是一个纯javascript模板引擎,支持IF和FOR关键字,多循环衔套及字段渲染,跨浏览器支持。是一个实用的javascipt工具,页面静态化利器!

示例代码:

alert(dotpl.applyTpl("hello ${val}", {val:"world"}));  
alert(dotpl.applyTpl("hello ${val} ${val2}", {val:"world",val1:"wide-web",val2:"good"}, function(k,v,kv){  
        if(k=='val') return kv['val']+"-"+kv['val1'];  
}));  
alert(dotpl.applyTpl("hello ${data.val}", {data:{val:"freedom"}}));  
alert(dotpl.applyTpl("hello ${data.val} nothing ${none}", {data:{val:"freedom"}}));  
alert(dotpl.applyTpl("hello ${val},<tpl if=\"'${action}'=='love'\">i ${action} you</tpl>", 
 {val:"town", action:'love'}));   
alert(dotpl.applyTpl("list:\n<tpl for=\"data\">${__offset} hello ${key} ${val}\n</tpl> 
list2:\n<tpl for=\"data\">${__offset} 1024 ${key} ${val}\n</tpl>",  
{data:[{key:"world", val:'like'},{key:"town", val:'freedom'}]}));