salak-view
View for SalakJS 2.0, support for multiple view engine, using consolidate under the hood.
Install
$ npm install --save salak-view
If you want to use ejs engine, You need install ejs.
$ npm install --save ejs
Usage
Config
In plugin:
moduleexports = plugin: name: 'view' package: 'salak-view' view: dirname: 'view' extension: 'html' engine: '' cache: true map: null config: {}
Use in Context or Controller
user/controller/login.js
const Controller = async { await this } moduleexports = Login
API
Options
- dirname {String} directory for storing views, default
view
- extension {String} template file extension, default
html
- engine {String} Engine for parse file, default ``
- cache {Boolean} Cache things for reading the file content, default
app.env === 'production'
- map {Object} map a file extension to an engine, like
{ html: 'ejs' }
, defaultnull
- config {Object} pass to view engine, default
{}
Controller.prototype.render(viewName, locals, module)
The function which register on or
- name {String} view filename
- locals {Object} variables for view
- module {String} the view located in, default: the current module
@return will set view html to response.body
context.render()
, but module
default app.root
Controller.prototype.renderView(viewName, locals, module)
params is the same as Controller.prototype.renderView
@return complied html string,if file ext
is html
and !options.engine && !map
, will return fs.createReadStrem(file)
context.renderView()
, but module
default app.root