Nunjuck官网文档提供演示代码如下,没能生效,演示代码如下。
var nunjucks = require('nunjucks');
var env = new nunjucks.Environment();
env.addFilter('shorten', function(str, count) {
return str.slice(0, count || 5);
});
添加了loader也没用,代码如下:
var nunjucks = require('nunjucks');
var env = new nunjucks.Environment(new nunjucks.FileSystemLoader('app/view'));
//app.js代码
class AppBootHook {
constructor(app) {
this.app = app;
}
configWillLoad() {
env.addFilter('shorten', function(str, count) {
return str.slice(0, count || 5);
});
}
}