eggjs/egg-view-nunjucks

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

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

egg-view-nunjucks

NPM version build status Test coverage David deps Known Vulnerabilities npm download

nunjucks view plugin for egg.

Install
m i egg-view-nunjucks --save
Usage
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' });


Feature
Filter
app_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' });


Tag

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);

Security

see egg-security

Helper / Locals
More
Configuration

see config/config.default.js for more detail.

Questions & Suggestions

Please open an issue here.

License

MIT


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.