Skip to content

Commit

Permalink
Add docs for template options (#156)
Browse files Browse the repository at this point in the history
This adds some docs for the template options, both global and local
  • Loading branch information
allouis authored Apr 3, 2019
1 parent ebb6112 commit c24cead
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ Create isolated engine instances with their own cache system and handlebars engi
var instance1 = hbs.create();
var instance2 = hbs.create();

## Template options

The main use case for template options is setting the handlebars "data" object - this creates global template variables accessible with an `@` prefix.

Template options can be set in 3 ways. When setting global template options they can be [passed as config on creation of an instance](https://github.com/barc/express-hbs#usage), and they can also be updated used the `updateTemplateOptions(templateOptions)` method of an instance. To set template options for an individual request they can be set on `res.locals` using the helper method `updateLocalTemplateOptions(locals, templateOptions)`.

Both of these methods have a companion method `getTemplateOptions()` and `getLocalTemplateOptions(locals)`, which should be used when extending or merging the current options.

## Example

in File `app.js`
Expand Down

0 comments on commit c24cead

Please sign in to comment.