thinkjs2.x 配置 art-template 模板引擎
一、thinkjs2.x默认模板引擎用的是ejs,改用art-template,art-template 是一个简约、超快的模板引擎(https://aui.github.io/art-template/zh-cn/docs/)。
二、切换到项目更目录安装art-template依赖:
安装命令:npm install art-template@^3.0.3 --save
三、在项目的src\common\adapter\template目录下新建art-template.js文件
命令: thinkjs adapter template/art-template
修改art-template.js文件代码:
'use strict';
/**
* base adapter
*/
import template from "art-template";
export default class extends think.adapter.base {
/**
* init
* @return {[]} []
*/
init(...args){
super.init(...args);
}
run(templateFile, tVar, config) {
template.config('extname', "");
if (this.env != "production") {
template.config("cache", false);
}
return template(templateFile, tVar);
}
}
四、修改src\common\config目录下view.js文件
'use strict';
/**
* template config
*/
import template from "art-template";
export default {
type: 'art-template',
content_type: 'text/html',
file_ext: '.html',
file_depr: '_',
root_path: think.ROOT_PATH + '/view',
adapter: {
}
};
到此, art-template模板引擎配置完成.
|
作者:onlystrive 出处:http://www.cnblogs.com/zyuc/ 本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。 |
posted on 2018-06-20 11:32 onlystrive 阅读(271) 评论(0) 收藏 举报
浙公网安备 33010602011771号