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')returnkv['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},<tplif=\"'${action}'=='love'\">i${action}you</tpl>", {val:"town",action:'love'}));alert(dotpl.applyTpl("list:\n<tplfor=\"data\">${__offset}hello${key}${val}\n</tpl> list2:\n<tplfor=\"data\">${__offset}1024${key}${val}\n</tpl>", {data:[{key:"world",val:'like'},{key:"town",val:'freedom'}]}));
评论