think-view-nunjucks
TypeScript icon, indicating that this package has built-in type declarations

1.0.11 • Public • Published

think-view-nunjucks

Build Status Coverage Status npm

Install

npm install think-view-nunjucks

How to Usage

edit config file src/config/adapter.js, add options:

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

const defaultOptions = {
  autoescape: true,
  watch: false,
  noCache: false,
  throwOnUndefined: false
};

change options:

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:

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

Readme

Keywords

Package Sidebar

Install

npm i think-view-nunjucks

Weekly Downloads

154

Version

1.0.11

License

ISC

Unpacked Size

8.26 kB

Total Files

11

Last publish

Collaborators

  • lizheming
  • welefen
  • sijiecai
  • lushijie
  • berwin
  • bezos
  • toxicjohann
  • huangxiaolu