Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thinkjs/think-view-handlebars
Use handlebars to render view files for ThinkJS 3.x
https://github.com/thinkjs/think-view-handlebars
handlebars think-adapter thinkjs thinkjs3 view
Last synced: about 1 month ago
JSON representation
Use handlebars to render view files for ThinkJS 3.x
- Host: GitHub
- URL: https://github.com/thinkjs/think-view-handlebars
- Owner: thinkjs
- License: mit
- Created: 2017-03-10T11:20:16.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2021-07-02T00:09:14.000Z (over 3 years ago)
- Last Synced: 2024-08-03T18:15:44.741Z (4 months ago)
- Topics: handlebars, think-adapter, thinkjs, thinkjs3, view
- Language: JavaScript
- Homepage:
- Size: 26.4 KB
- Stars: 0
- Watchers: 9
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- think-awesome - think-view-handlebars
README
# think-view-handlebars
[![Build Status](https://travis-ci.org/thinkjs/think-view-handlebars.svg?branch=master)](https://travis-ci.org/thinkjs/think-view-handlebars)
[![Coverage Status](https://coveralls.io/repos/github/thinkjs/think-view-handlebars/badge.svg?branch=master)](https://coveralls.io/github/thinkjs/think-view-handlebars?branch=master)
[![npm](https://img.shields.io/npm/v/think-view-handlebars.svg?style=flat-square)](https://www.npmjs.com/package/think-view-handlebars)## Install
```
npm install think-view-handlebars
```## Usage
edit config file `src/config/adapter.js`, add options:
```js
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
```js
const defaultOptions = {
compat: true,
strict: false,
preventIndent: true,
ignoreStandalone: true,
cache: false
};
```change options:
```js
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
```js
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