代码拉取完成,页面将自动刷新
A lightweight, high-performance JavaScript template engine.
npm install gotpl --save
<script>
IncludeSimply download and include with a script tag. playable
will be registered as a global variable.
<script src="https://cdn.jsdelivr.net/npm/gotpl/dist/gotpl.min.js"></script>
You can browse the source of the NPM package at cdn.jsdelivr.net/npm/gotpl.
$ npm run test
You can also check the test report in your browser.
<h1>Projects</h1>
<ul id="list"></ul>
<% if (projects.length) { %>
<% for (var i = 0, l = projects.length; i < l; ++i) { %>
<% var item = projects[i]; %>
<li class="item">
<a target="_blank" href="<%=item.url%>"><%= item.name %></a>
</li>
<% } %>
<% } %>
var data = {
projects: [{
"name": "gotpl",
"url": "https://github.com/Lanfei/gotpl"
}, {
"name": "playable.js",
"url": "https://github.com/Lanfei/playable.js"
}, {
"name": "webpack-isomorphic",
"url": "https://github.com/Lanfei/webpack-isomorphic"
}, {
"name": "websocket-lib",
"url": "https://github.com/Lanfei/websocket-lib"
}, {
"name": "node-cd-cluster",
"url": "https://github.com/Lanfei/node-cd-cluster"
}]
};
var tpl = document.getElementById('tpl').innerHTML;
document.getElementById('list').innerHTML = gotpl.render(tpl, data);
gotpl.config(options);
gotpl.render(template, data, options);
gotpl.renderFileSync(path, data, options);
gotpl.renderFile(path, data, options, (err, html) => {
// Your codes.
});
await gotpl.renderFile(path, data, options);
// Cache the compiled function
let fn = gotpl.compile(template, options);
fn(data);
app.engine('tpl', template.renderFile);
app.set('view engine', 'tpl');
root
The root of template filesscope
Rendering context, defaults to global
in node, window
in browserdebug
Enable debug information output, defaults to false
cache
Enable caching, defaults to true
minify
Minify indents, defaults to true
openTag
Open tag, defaults to <%
closeTag
Close tag, defaults to %>
<% code %>
Logic code<%= value =>
Output the value as escaped HTML<%- value %>
Output the value as unescaped HTMLUse include(path[, data, options])
function to import partial templates, and use <%- value %>
tag to output:
<h1>Projects</h1>
<ul id="list"></ul>
<% if (projects.length) { %>
<% for (var i = 0, l = projects.length; i < l; ++i) { %>
<%- include('project', projects[i]) %>
<% } %>
<% } %>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型