分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 运营维护

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

发布时间:2023-09-06 02:00责任编辑:赖小花关键词:js配置模板引擎

一、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 模板引擎

原文地址:https://www.cnblogs.com/zyuc/p/9202968.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved