Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

Awesome Lists containing this project

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