https://github.com/thinkjs/think-view-nunjucks
Use nunjucks to render view files for ThinkJS 3.x
https://github.com/thinkjs/think-view-nunjucks
nunjucks think-adapter thinkjs3 view
Last synced: 2 months ago
JSON representation
Use nunjucks to render view files for ThinkJS 3.x
- Host: GitHub
- URL: https://github.com/thinkjs/think-view-nunjucks
- Owner: thinkjs
- License: mit
- Created: 2017-03-06T07:46:50.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2021-07-01T00:25:59.000Z (almost 4 years ago)
- Last Synced: 2025-01-30T19:11:26.002Z (3 months ago)
- Topics: nunjucks, think-adapter, thinkjs3, view
- Language: JavaScript
- Homepage:
- Size: 23.4 KB
- Stars: 2
- Watchers: 9
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- think-awesome - think-view-nunjucks
README
# think-view-nunjucks
[](https://travis-ci.org/thinkjs/think-view-nunjucks)
[](https://coveralls.io/github/thinkjs/think-view-nunjucks?branch=master)
[](https://www.npmjs.com/package/think-view-nunjucks)## Install
```
npm install think-view-nunjucks
```## How to Usage
edit config file `src/config/adapter.js`, add options:
```js
const nunjucks = require('think-view-nunjucks');
exports.view = {
type: 'nunjucks',
common: {
viewPath: path.join(think.ROOT_PATH, 'view'),
extname: '.html',
sep: '_' //seperator between controller and action
},
nunjucks: {
handle: nunjucks,
beforeRender: (env, nunjucks, config) => {}
}
}
```### default options
```js
const defaultOptions = {
autoescape: true,
watch: false,
noCache: false,
throwOnUndefined: false
};
```
### change options:```js
exports.view = {
type: 'nunjucks',
nunjucks: {
handle: nunjucks,
options: {
tags: {
blockStart: '<%',
blockEnd: '%>',
variableStart: '<$',
variableEnd: '$>',
commentStart: '<#',
commentEnd: '#>'
}
},
beforeRender: (env, nunjucks, handleOptions) => {}
}
}
```
you can find all nunjucks support options at https://mozilla.github.io/nunjucks/api.html#configure### beforeRender
you can use `beforeRender` method to set some env:
```js
exports.view = {
type: 'nunjucks',
nunjucks: {
handle: nunjucks,
beforeRender: (env, nunjucks, handleOptions) => {
env.addGlobal('think', think);
env.addGlobal('JSON', JSON);
}
}
}
```
you can find all APIs in `env` at https://mozilla.github.io/nunjucks/api.html#environment