Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thinkjs/think-view-ejs
compile view templates with EJS for ThinkJS 3.x
https://github.com/thinkjs/think-view-ejs
ejs think-adapter thinkjs3 view
Last synced: about 1 month ago
JSON representation
compile view templates with EJS for ThinkJS 3.x
- Host: GitHub
- URL: https://github.com/thinkjs/think-view-ejs
- Owner: thinkjs
- License: mit
- Created: 2017-03-13T02:12:10.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-12-23T04:46:15.000Z (almost 5 years ago)
- Last Synced: 2024-08-03T18:15:46.609Z (4 months ago)
- Topics: ejs, think-adapter, thinkjs3, view
- Language: JavaScript
- Size: 9.77 KB
- Stars: 5
- Watchers: 10
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- think-awesome - think-view-ejs
README
# think-view-ejs
[![Build Status](https://img.shields.io/travis/thinkjs/think-view-ejs/master.svg?style=flat-square)](https://travis-ci.org/thinkjs/think-view-ejs)
[![Coverage Status](https://img.shields.io/coveralls/thinkjs/think-view-ejs/master.svg?style=flat-square)](https://coveralls.io/github/thinkjs/think-view-ejs?branch=master)
[![npm](https://img.shields.io/npm/v/think-view-ejs.svg?colorB=brightgreen&style=flat-square)](https://www.npmjs.com/package/think-view-ejs)Compile view templates with EJS for ThinkJS 3.x.
## Install
```
npm install think-view-ejs
```
## Usageedit config file `src/config/adapter.js`, add options for ejs adapter:
```js
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:
```js
const defaultOptions = {
cache: true
}
```You can override it and add other options by editing file `src/config/adapter.js` :
```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](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