# 模板引擎 默认模板引擎 nunjucks (opens new window)

  1. 在 controller 里新建个 test.js
const Base = require("./base.js");
module.exports = class extends Base {
  async indexAction() {
    const model = this.model("app_issue");
    const res = await model.where({ id: this.get("id") || 1 }).find();
    res.screenshot = res.screenshot.split(",");
    this.assign(res); //模板里需要的参数
    return this.display();
  }
};
1
2
3
4
5
6
7
8
9
10
  1. 在 view 目录下新建 fabu_index.html
{% include "nav_head.html" %} #插入html
<img src="{{logo}}" class="app-logo" /> # {{logo}}输入模板返回的值
<div>
  {% for item in screenshot %} #循环方法
  <img src="{{item}}" />
  {% endfor %}
</div>
1
2
3
4
5
6
7