1. 程式人生 > >08koa art-template 模板引擎

08koa art-template 模板引擎

一、常見模板引擎的效能對比
適用於 koa 的模板引擎選擇非常多,比如 jade、ejs、nunjucks、art-template 等。

	art-template 是一個簡約、超快的模板引擎。它採用作用域預宣告的技術來優化模板渲染速度,從而獲得接近 JavaScript 極限的執行效能,並且同時支援 NodeJS 和瀏覽器。art-template 支援 ejs 的語法,也可以用自己的類似 angular 資料繫結的語法

學習使用art-template最好的方法就是參照一下兩個途徑:

官網:http://aui.github.io/art-template/
中文文件: http://aui.github.io/art-template/zh-cn/docs/

二、在 Koa 中使用 art-template 模板引擎

和之前Koa模組一樣,art-template模組在使用前需要配置art-template。

	npm install --save art-template
	npm install --save koa-art-template

	const Koa = require('koa');
	const render = require('koa-art-template');

	const app = new Koa();
	render(app, {
	root: path.join(__dirname, 'view'), extname: '.art', debug: 			process.env.NODE_ENV !== 'production' });
	app.use(async function (ctx) {
	await ctx.render('user');
	});
	app.listen(3000);

三、art-template 模板引擎語法

剩下的相關語法參照下面網站:

http://aui.github.io/art-template/zh-cn/docs/syntax.html