egg开发系列--模板语法
在这里列一下 nunjucks 常用的模板内容
首先需要在plugin.js 当中引入
exports.nunjucks = { enable: true, package: 'egg-view-nunjucks' };
1、变量传入 {{ title }} 2、for循环 {% for item in list %} {{ item.id }} {% endfor %} 3、if语句,多条件使用:and, or, not {% if i < 0 %} 条件内容 {% elif i >=0 and i < 100 %} 条件内容 {% else %} 条件内容 {% endif %} 4、三目运算 {{ "是" if isVip == 1 else "否" }} 5、引入其他模板 {% include "../header.html" %}