默认 view目录是 /app/view

多个路径配置

config.default.js

  1. const path = require('path');
  2. config.view = {
  3. root: [
  4. path.join(appInfo.baseDir, 'app/view'),
  5. path.join(appInfo.baseDir, 'path/to/another'),
  6. ].join(',')
  7. };

view模板里面,可以获取到 helper工具类

  1. // service
  2. ctx.helper.fromNow(it.created_at)
  3. // nunjucks模板
  4. {{helper.fromNow(it.created_at)}}