1. 程式人生 > >thinkjs2.x 配置 art-template 模板引擎

thinkjs2.x 配置 art-template 模板引擎

highlight config AD think IE java blank TE body

一、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/

本文版權歸作者所有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連接。

thinkjs2.x 配置 art-template 模板引擎