# mgp-tpl **Repository Path**: dszj/mgp-tpl ## Basic Information - **Project Name**: mgp-tpl - **Description**: 超级简单的模板引擎 - **Primary Language**: JavaScript - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2017-04-20 - **Last Updated**: 2020-12-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README #mgp-tpl 简单的模板引擎,仅仅把模板和上下文合并后输入,没有预编译功能。 语法:用<%和%>把js代码包裹起来,仅此而已 模板例子 ```javascript //模板 var tmpl='

<%=title%>

\ \ <% for (var i=0;i\ //js的for循环 //<%= %>用来直接输出变量,用过jsp的都懂得 \ <% } %>\
<%=i %>
\ <%=(count>10)%>\ ' //上下文 var obj={ title:'这个一个模板测试', count:5, content:'hello world!' } //mgpTpl便是模板的对象,调用compile方法就能把模板和上下文组装起来。返回组装字符串结果 var res=mgpTpl.compile(tmpl,obj); console.log(res) ``` $$ x = \dfrac{-b \pm \sqrt{b^2 - 4ac}}{2a} $$