有没有用nunjucks模板引擎的?怎么自定义过滤器?
https://mozilla.github.io/nunjucks/api.html#custom-filters
@jpuncle 跟node一起用好像无效啊会出现 filter not found 难道用的方式不对?
@allce231 没代码不好判断
我这样用的,写了一个判断字符串是否在数组里,你参考一下
var env = nunjucks.configure('views', { autoescape: true, express: app, noCache: true, web: { useCache: false } }); env.addFilter('contains', function(arr, str) { if (arr instanceof Array) { for (var index = 0; index < arr.length; index++) { if (arr[index] === str) { return true; } } } return false; });
@liygheart 感谢
CNode 社区为国内最专业的 Node.js 开源技术社区,致力于 Node.js 的技术研究。
https://mozilla.github.io/nunjucks/api.html#custom-filters
@jpuncle 跟node一起用好像无效啊会出现 filter not found 难道用的方式不对?
@allce231 没代码不好判断
我这样用的,写了一个判断字符串是否在数组里,你参考一下
@liygheart 感谢