Is it possible to call a js function and pass a variable into nunjucks template..?
{{ filter }}
{% set filterParam = orderBy() %}
{{ filter }}
{% for item in items | sort(true, true, filterParam) %}
const env = new nunjucks.Environment(/* ...loaders etc... */);
装载机是什么意思?
To use a function inside a template you should define it as global.
const nunjucks = require('nunjucks');
const env = new nunjucks.Environment(/* ...loaders etc... */); // or nunjucks.configure(...)
env.addGlobal('foo', () => 'OK');
const out = env.renderString(`{{ foo () }}`);
console.log(out);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.