EasyTemplateJS-koa
EasyTemplateJS-koa 是基于 EasyTemplateJS 的 koa 框架的模板引擎中间件。
EasyTemplateJS-koa is a template engine middleware based on EasyTemplateJS for the koa framework.
Npm install
npm install easytemplatejs-koa
Usage
const app = new Koa();
const view = require('easytemplatejs-koa');
view(app, {
cache: true,
enableScript:true,
enableStyle:true,
views: path.join(__dirname, './views'),
ext: 'etj'
});
Demo
-
app.js
const Koa = require('koa');
const path = require('path');
const app = new Koa();
const view = require('easytemplatejs-koa');
view(app, {
views: path.join(__dirname, './views'),
ext: 'etj'
});
app.use(async ctx => {
await ctx.render('user', {
name: 'Jay',
list:[
{name:"Jay", sex:'M'},
{name:"Rose", sex:'F'},
{name:"Anna ", sex:'F'}
]
});
});
app.listen(3000);
-
./views/user.etj
<h1>Hello {=name}!</h1>
<ul>
%{
for(var i=0;i<list.length;i++){
out('<li>'+list[i].name+", "+list[i].sex+'</li>');
}
}%
</ul>
EasyTemplateJS Core Object
如果需要获得 EasyTemplateJS 的核心对象进行调用,可通过中间件函数的 .templateEngine
属性获得。
If you need to get the core object of EasyTemplateJS to make a call, you can get it use the .templateEngine
property of the middleware function.
const view = require('easytemplatejs-express');
var Et=view.templateEngine;
Et.tmplSettings={
scriptBegin:"%{",
scriptEnd:"}%",
outBegin:"{=",
outEnd:"}",
escapeOutBegin:"{-",
escapeOutEnd:"}"
}
内嵌 Script 和 CSS 支持/Embedded JavaScript and CSS
view(app, {
enableScript:true,
enableStyle:true,
...
});
中文
为了增强在 Express 等服务端 Web 应用框架中使用模板的功能体验,EasyTemplateJS 开创性的为模板提供了 script 脚本和 style 样式表支持。
English
To enhance the functional experience of using templates in Express and other server-side Web application frameworks, EasyTemplateJS pioneered the provision of script scripts and style style sheet support for templates.
EasyTemplateJS
Documents
End
Email:inthinkcolor@gmail.com
http://www.easyproject.cn
支付宝钱包扫一扫捐助:
我们相信,每个人的点滴贡献,都将是推动产生更多、更好免费开源产品的一大步。
感谢慷慨捐助,以支持服务器运行和鼓励更多社区成员。
We believe that the contribution of each bit by bit, will be driven to produce more and better free and open source products a big step.
Thank you donation to support the server running and encourage more community members.