https://github.com/dadi/web-handlebars
A Handlebars.js interface for DADI Web
https://github.com/dadi/web-handlebars
Last synced: about 2 months ago
JSON representation
A Handlebars.js interface for DADI Web
- Host: GitHub
- URL: https://github.com/dadi/web-handlebars
- Owner: dadi
- Created: 2017-07-10T11:32:56.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2019-05-02T09:24:12.000Z (about 7 years ago)
- Last Synced: 2025-10-19T09:34:06.153Z (8 months ago)
- Language: JavaScript
- Size: 67.4 KB
- Stars: 0
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README

## Handlebars.js engine interface
[](https://www.npmjs.com/package/@dadi/web-handlebars)
[](https://coveralls.io/github/dadi/web-handlebars?branch=master)
[](https://travis-ci.org/dadi/web-handlebars)
[](http://standardjs.com/)
This module allows [Handlebars.js](http://handlebarsjs.com/) templates to be used with [DADI Web](https://github.com/dadi/web).
## Installation
- Add this module as a dependency:
```
npm install @dadi/web-handlebars --save
```
- Include it in the `engines` array passed to Web:
```js
require('@dadi/web')({
engines: [
require('@dadi/web-handlebars')
]
})
```
## Configuration
The following configuration parameters can be added to the global Web config file, under `engines.handlebars`.
### `paths`
Paths required by Handlebars.
- Format: `Object`
- Default:
```
{
{
helpers: 'workspace/utils/helpers'
}
}
```
## Partials
Partials must be registered with Handlebars before they can be used in a template. This library takes care of the registration for you, simply supply the path to your partials in the configuration option `additionalTemplates`.
```
pages/
|_ partials/
|_ |_ common/
|_ |_ |_ header.hbs
|_ contact-info.hbs
|_ home.hbs
```
Partials are referenced by their relative path, minus the file extension. After loading the above hierarchy of templates and partials, to include `header.hbs` from the page `contact-info.hbs`, you would use the following syntax:
```hbs
{{> 'partials/common/header' }}
```
See the [Handlebars documentation](http://handlebarsjs.com/partials.html) for more information regarding the use of partials.
## Helpers
To use helpers supply the path to your helpers in the main Web configuration file:
```json
"engines": {
"handlebars": {
"paths": {
"helpers": "workspace/helpers"
}
}
}
```
Helpers can be individual JavaScript files within the specifed directory, or all in a single file.
*Example:*
```js
const handlebars = require('handlebars')
/*
* Returns the full name and price of the supplied product
* Usage: {{ renderProduct product }}
*/
handlebars.registerHelper('renderProduct', product => {
return `helper: ${product.name} - £${product.price}`
})
```