1.0.9 • Published 3 years ago

think-view-handlebars v1.0.9

Weekly downloads
1
License
ISC
Repository
github
Last release
3 years ago

think-view-handlebars

Build Status Coverage Status npm

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

1.0.9

3 years ago

1.0.8

4 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago