think-view-handlebars
v1.0.9
Published
Handlebars view adapter for ThinkJS
Downloads
8
Keywords
Readme
think-view-handlebars
Install
npm install think-view-handlebars
Usage
edit config file src/config/adapter.js
, add options:
const handlebars = require('think-view-handlebars');
exports.view = {
type: 'handlebars',
common: {
viewPath: path.join(think.ROOT_PATH, 'view'),
extname: '.html',
sep: '_' //seperator between controller and action
},
handlebars: {
handle: handlebars,
beforeRender: (handlebars, handleOptions) => {
// todo
}
}
}
default options
const defaultOptions = {
compat: true,
strict: false,
preventIndent: true,
ignoreStandalone: true,
cache: false
};
change options:
exports.view = {
type: 'handlebars',
handlebars: {
handle: handlebars,
options: {
strict: true
},
beforeRender: (handlebars, handleOptions) => {
// todo
}
}
}
you can find all handlebars's support options at http://handlebarsjs.com/reference.html
beforeRender
exports.view = {
type: 'handlebars',
handlebars: {
handle: handlebars,
beforeRender: (handlebars, handleOptions) => {
handlebars.registerHelper("studyStatus", function(passingYear) {
if(passingYear < 2017) {
return "passed";
} else {
return "not passed";
}
})
}
}
}
you can find all APIs at http://handlebarsjs.com/reference.html