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

0.0.13 • Public • Published

think-view-ejs

Build Status Coverage Status npm

Compile view templates with EJS for ThinkJS 3.x.

Install

npm install think-view-ejs

Usage

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

const ejs = require('think-view-ejs');
exports.view = {
  type: 'ejs',
  common: {
    viewPath: path.join(think.ROOT_PATH, 'view'),
    extname: '.html',
    sep: '_' //seperator between controller and action
  },
  ejs: {
    //options
    handle: ejs,
    beforeRender: (ejs, handleOptions) => {
      //do something before render the template.
    }
  }
}

Options

Default options:

const defaultOptions = {
  cache: true
}

You can override it and add other options by editing file src/config/adapter.js :

exports.view = {
  type: 'ejs',
  ejs: {
    handle: ejs,
    options: {
      //override `cache` option
      cache: false
    },
    beforeRender: (ejs, handleOptions) => {
      //do something before render the template.
    }
  }
}

Please refer to https://github.com/mde/ejs#options for more information on EJS options.

beforeRender

beforeRender is a function that you can handle something before rendering the template file. It exposes 2 parameters:

  • ejs — the original ejs module
  • handleOptions — current configure of ejs adapter

Readme

Keywords

none

Package Sidebar

Install

npm i think-view-ejs

Weekly Downloads

1

Version

0.0.13

License

none

Unpacked Size

7.09 kB

Total Files

8

Last publish

Collaborators

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