-------------
m1.html 模板文件
{#
m1 hbox 横向滚动抽屉
#}
<div class="heading">
<div class="title" style="padding:0.5rem;"><h3>{*data.name*}</h3></div>
<nav class="nav">
<a><i class="icon icon-sort-by-attributes-alt"></i></a>
</nav>
</div>
{%foreach v in data.data do%}
<a class="item with-avatar multi-lines" data-item="{*v.book_id*}">
<div class="avatar rounded yellow" style="pointer-events:none;width:3.6rem;height:4.5rem">
<img src="res/{*v.book_id*}/icon.jpg">
</div>
<div class="content" style="pointer-events:none;">
<div class="title" style="color:#000;pointer-events:none; font-bold:100; padding-left:5px; font-size:0.7rem">{*v.name*}</div>
<div class="subtitle" style="padding-left:5px;pointer-events:none; font-size:0.6rem;line-height:0.8rem;">
{%if (v.keyword.length>50) do%}
{*v.keyword.substring(0,50)*} ...
{%else%}
{*v.keyword*}
{%end%}<br>
<span>{*v.author*} | {*v.book_type*} | {*v.status*}</span>
</div>
</div>
</a>
{%end%}
m3.html 模板
{#
m3有图标也有简介的模块视图
#}
<div class="heading">
<div class="title" style="padding:0.5rem;"><h3>{*data.name*}</h3></div>
<nav class="nav">
<a><i class="icon icon-sort-by-attributes-alt"></i></a>
</nav>
</div>
{%foreach v in data.data do%}
<a class="item with-avatar multi-lines" data-item="{*v.book_id*}">
<div class="avatar rounded yellow" style="pointer-events:none;width:3.6rem;height:4.5rem">
<img src="res/{*v.book_id*}/icon.jpg">
</div>
<div class="content" style="pointer-events:none;">
<div class="title" style="color:#000;pointer-events:none; font-bold:100; padding-left:5px; font-size:0.7rem">{*v.name*}</div>
<div class="subtitle" style="padding-left:5px;pointer-events:none; font-size:0.6rem;line-height:0.8rem;">
{%if (v.keyword.length>50) do%}
{*v.keyword.substring(0,50)*} ...
{%else%}
{*v.keyword*}
{%end%}<br>
<span>{*v.author*} | {*v.book_type*} | {*v.status*}</span>
</div>
</div>
</a>
{%end%}
m4.html 模板文件
{#
m4是首元素权限其余元素只显示图标
#}
<div class="heading">
<div class="title" style="padding:0.5rem;"><h3>{*data.name*}</h3></div>
<nav class="nav">
<a><i class="icon icon-sort-by-attributes-alt"></i></a>
</nav>
</div>
{%header = true;%}
{%foreach v in data.data do%}
{%if (header==true) do%}
<a class="item with-avatar multi-lines" data-item="{*v.book_id*}">
<div class="avatar rounded yellow" style="pointer-events:none;width:3.6rem;height:4.5rem">
<img src="res/{*v.book_id*}/icon.jpg">
</div>
<div class="content" style="pointer-events:none;">
<div class="title" style="color:#000;pointer-events:none; font-bold:100; padding-left:5px; font-size:0.7rem">{*v.name*}</div>
<div class="subtitle" style="padding-left:5px;pointer-events:none; font-size:0.6rem;line-height:0.8rem;">
{%if (v.keyword.length>50) do%}
{*v.keyword.substring(0,50)*} ...
{%else%}
{*v.keyword*}
{%end%}<br>
<span>{*v.author*} | {*v.book_type*} | {*v.status*}</span>
</div>
</div>
</a>
{%header = false%}
<div class="row">
{%else%}
<div class="cell-3" style="padding:.7rem ;">
<a class="item with-avatar multi-lines" data-item="{*v.book_id*}">
<div class="avatar rounded yellow" style="pointer-events:none;width:3.6rem;height:4.5rem">
<img src="res/{*v.book_id*}/icon.jpg">
</div>
<div class="content" style="pointer-events:none;">
<div class="subtitle" style="font-size:0.6rem;line-height:0.8rem; padding-top:0.5rem;">{*v.name*}</div>
</div>
</a>
</div>
{%end%}
{%end%}
</div>
-------------
//生成一个二进制的模板代码压缩文件
var template = require("./template.js").template;
template.info();
var a = template.precompile("./" , "a.out");
template.load("a.out");
输入文件夹 输出2进制文件,输出2进制文件可通过浏览器示例处理。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="template.js"></script>
</head>
<body>
<script>
template.load("a.out", function (){
console.time ("t")
for(var i = 0; i< 1000000; i++) {
template.render("head.html" , {name:"agent.zy"});
}
console.timeEnd ("t")
});
console.log(template)
</script>
</body>
</html>
var template = require("./template.js").template;
var helloPtr = template.compile("{{name}}, welcome!");
console.log(helloPtr({ name : "agent.zy" }));
{{expression}}
内容语法<header>
<div id="{{name}}">
""
</div>
<div id="{{name}}">
""
</div>
<div id="{{name}}" >
"{{ddd}}"
</div>
</header>
{*expression*}
变量语法var template = require("./template.js").template;
template.info();
console.log(template.compile('{*data["foo"]*}' , 1)());
var tml5 = "{%\
var a = 10\
%}"
var tml6 = "condition {*a*}";
console.log( tml5 + tml6);
var a = template.compile(tml5 + tml6 , 2);
console.log("result:",a({"k1":2,"k2":"v2"}));
{%expression%}
逻辑语法if 语句
var template = require("./template.js").template;
template.info();
var str = `
{% if (data['k1']==1) do %}
value eq 1 out
{%else%}
value neq 1 out
{%end%}
`
console.log( "tml=" , str );
var a = template.compile(str , 2);
console.log("===============");
console.log("result:", a({"k1":2,"k2":"v2"}));
for each
var template = require("./template.js").template;
template.info();
var str = `
{%foreach v in data do%}
{*v*} {%EOL%}
{%end%}
`
var a = template.compile(str , 3);
console.log("result:",a({"k1":"v1","k2":"v2"}));
for in
var template = require("./template.js").template;
template.info();
var str = `
{%for d in data do%}
key 是{*d*} 并且元素是 {*data[d]*} 换行 {%EOL%}
{%end%}
`
console.log( str );
var a = template.compile(str , 2);
console.log("result:",a({"k1":"frist","k2":"second"}));
ipairs 语法
var template = require("./template.js").template;
template.info();
var tml8 = "{%\
ipairs i,v in data do\
%}"
var tml9 = " {*i*} {*v.k1*} {%EOL%}";
var tml10 = "{%end%}"
var a = template.compile(tml8 + tml9 + tml10 , 3);
console.log("result:",a([{"k1":"v1"},{"k1":"v2"},{"k1":"v3"} ]));
{#expression#}
注释语法注释语法
var template = require("./template.js").template;
template.info();
var tml8 = "{# \
this is a note !!!\
#} hello {# this is note !!!#}222"
var a = template.compile(tml8 , 3);
console.log("result:",a({"k1":"v1","k2":"v2"}));
{#expression#}
继承语法模板继承语法 组合
var template = require("./template.js").template;
template.info();
var tml8 = "{(head.html)} TML {# this is note !!!#}222 TML"
var a = template.compile(tml8 , 3);
console.log("result=",a({"name":"v1","k2":"v2"}));
js模板引擎template.js的使用 template.js源码 /*!art-template - Template Engine | http://aui.github.com/artTemplate/*/ !function(){function a(a){return a.replace(t,"").replace(u,",").replace(v,"").replace(w,"").
template.js是一款开源的JavaScript模板引擎,用来渲染页面的 第一步:首页页面引用 <script type="text/javascript" src="js/template.js"></script> 第二步:模板创建 <!-- 模版 --> <script type="text/html" id="templet"> {{each object as obj i}}
\s 空白字符,包括: \b space character 空格符 \n new line character 换行符 \v vertical tab character 垂直换行符 \r 回车符 carriage return character \t tab character 制表符 \b backspace character 空格符 \f form feed character 换页符
出现以下错误的原因是 :node-pre-gyp WARN Tried to download(404): https://fsevents-binaries.s3-us-west-2.amazonaws.com/v1.2.7/fse-v1.2.7-node-v83-darwin-x64.tar.gz 【下载失败,下载的路径记录在原有的package-lock.json,现在已打不开了,所有导致这
具体查看ejs官方文档 https://github.com/mde/ejs
我们自己实现了一个轻量级的模板引擎,不要问为什么不用smart之类的,因为我们认为没有必要为了一个小小的模板引擎而引入smaart这样复杂的实现。你可能会说,smart功能强大,支持各种标签,标签也是很强大,而且还可以对模板引擎进行各种"灵活"的配置... 这里我们觉得有必要说明一下: 框架的内置模板引擎基本上实现了我们日常开中所有常用的标签。 不常用的标签我们也做了巧妙的实现。 我们只提供了扩展
内置模板引擎 视图的模板文件可以支持不同的解析规则,默认情况下无需手动初始化模板引擎。 可以通过下面的几种方式对模板引擎进行初始化。 配置文件 内置模板引擎的参数统一在配置目录的template.php文件中配置,例如: return [ // 模板引擎类型 支持 php think 支持扩展 'type' => 'Think', // 模板路径 '
Warning: The packages listed below may be outdated, no longer maintained or even broken. Listing here does not constitute an endorsement or recommendation from the Expressjs project team. Use at your
Use the app.engine(ext, callback) method to create your own template engine. ext refers to the file extension, and callback is the template engine function, which accepts the following items as parame
hi-nginx-java内置了两个mustache模板引擎:mustache.java和jmustache。 以下介绍仅就jmustache而言。 字符串模板 字符串模板是最简单的情况。例如: package test; import hi.request; import hi.response; import hi.route; import java.util.regex.Matcher