think-template-art for ThinkJS
Install
npm install think-template-art
How to use
adapter
注册 添加文件src/common/bootstrap/adapter.js
.
;think;
配置
修改配置文件 src/common/config/view.js
:
type: 'art' content_type: 'text/html' file_ext: '.html' file_depr: '_' root_path: thinkROOT_PATH + '/view' helper_path: thinkRESOURCE_PATH+'/static/js/template.helper.js' adapter: ejs: {} art: //这里书写 art-template 配置,如果基础配置存在,将覆盖基础配置 ;
helper函数配置
修改 config/view
中的 helper_path
helper函数的格式为
!{ let helpers = {}; /** * 对日期进行格式化, * @param date 要格式化的日期 * @param format 进行格式化的模式字符串 * 支持的模式字母有: * y:年, * M:年中的月份(1-12), * d:月份中的天(1-31), * h:小时(0-23), * m:分(0-59), * s:秒(0-59), * S:毫秒(0-999), * q:季度(1-4) * @return String */ helpers { if toString != '[object Date]' date = date-0; var map = "M": date + 1 //月份 "d": date //日 "h": date //小时 "m": date //分 "s": date //秒 "q": Math //季度 "S": date //毫秒 ; console; format = format; return format; }; // RequireJS && SeaJS if typeof define === 'function' ; // NodeJS else if typeof exports !== 'undefined' moduleexports = helpers; else thishelpers = helpers; };
拷贝后放到你需要的位置
如果你需要同构页面务必把文件放到 /www/static
中
辅助方法的例子 | art-template文档 | ThinkJS文档
LICENSE
MIT