how to define Customer filter in nunjucks ?
wuchuguang opened this issue · 3 comments
wuchuguang commented
filter.js
import nunjucks from 'nunjucks';
let env = new nunjucks.Environment();
env.addFilter('sex', function(str){
switch (str){
case 1:
return "男";
default :
return "女";
}
});
module.exports = env;
module.exports = nunjucks;//or this
import filter from './filter';
app.use(views(__dirname + '/views', { options: {
nunjucksEnv:filter,
settings: {
views: path.join(__dirname, 'views')
}
},map: {html: 'nunjucks' }}))
but not validate
int64ago commented
module.exports = env;
module.exports = nunjucks;//or this
Why exported twice here ?
wuchuguang commented
when module.exports = env report nunjucks error
when module.exports = nunjucks report filter error
int64ago commented
I write an example for your case, hope it helps.