在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:strawbrary/koa-nunjucks-2开源软件地址:https://github.com/strawbrary/koa-nunjucks-2开源编程语言:JavaScript 95.0%开源软件介绍:koa-nunjucks-2Lightweight Koa middleware for Nunjucks. Installation
NOTE: v3 requires Koa 2 or later. If you're using Koa 1, use v2 of this package. UsageExampleconst Koa = require('koa');
const app = new Koa();
const koaNunjucks = require('koa-nunjucks-2');
const path = require('path');
app.use(koaNunjucks({
ext: 'html',
path: path.join(__dirname, 'views'),
nunjucksConfig: {
trimBlocks: true
}
}));
app.use(async (ctx) => {
await ctx.render('home', {double: 'rainbow'});
}); Config Options
Global Template VariablesUse ctx.state to make a variable available in all templates. Extending NunjucksUse the app.use(koaNunjucks({
ext: 'html',
path: path.join(__dirname, 'views'),
configureEnvironment: (env) => {
env.addFilter('shorten', (str, count) => {
return str.slice(0, count || 5);
});
}
})); License |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论