Name: egg-view-nunjucks
Owner: egg
Description: nunjucks view plugin for egg
Created: 2016-07-17 09:38:25.0
Updated: 2018-05-08 16:54:41.0
Pushed: 2018-03-29 09:37:28.0
Homepage: null
Size: 72
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
nunjucks view plugin for egg.
m i egg-view-nunjucks --save
app_root}/config/plugin.js
rts.nunjucks = {
able: true,
ckage: 'egg-view-nunjucks',
Set mapping in config
app_root}/config/config.default.js
rts.view = {
faultViewEngine: 'nunjucks',
pping: {
'.nj': 'nunjucks',
Render in controller
app_root}/app/controller/test.js
s TestController extends Controller {
ync list() {
const ctx = this.ctx;
// ctx.body = await ctx.renderString('{{ name }}', { name: 'local' });
// not need to assign `ctx.render` to `ctx.body`
await ctx.render('test.nj', { name: 'view test' });
escape
filter is replaced by helper.escape
which is provided by egg-security
for better performanceapp/extend/filter.js
, then they will be injected automatically to nunjucksapp_root}/app/extend/filter.js
rts.hello = name => `hi, ${name}`;
o you could use it at template
app_root}/app/controller/test.js
s TestController extends Controller {
ync list() {
const ctx = this.ctx;
ctx.body = await ctx.renderString('{{ name | hello }}', { name: 'egg' });
you can extend custom tag like this:
app_root}/app.js
t markdown = require('nunjucks-markdown');
t marked = require('marked');
le.exports = app => {
rkdown.register(app.nunjucks, marked);
see egg-security
_csrf
attr to form fieldnonce
attr to script taghelper/ctx/request
in template, such as helper.shtml('<div></div>')
helper.upper('test')
helper.shtml/surl/sjs/escape
is auto wrapped with safe
app.nunjucks
- nunjucks environmentapp.nunjucks.cleanCache(fullPath/tplName)
to easy clean cache, can use with custom egg-watchersee config/config.default.js for more detail.
Please open an issue here.