Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on May 17, 2026. It is now read-only.

thinkjs/think-view-nunjucks

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This repository has been migrated. For ongoing updates, please see https://github.com/thinkjs/thinkjs/tree/master/packages/think-view-nunjucks.

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

About

Use nunjucks to render view files for ThinkJS 3.x

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.