Skip to content

Commit a01e040

Browse files
committed
feat(engine-handlebars): Document the Helpers feature
1 parent 11c4180 commit a01e040

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

packages/engine-handlebars/README.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# The Handlebars PatternEngine for Pattern Lab / Node
22

3-
To install the Handlebars PatternEngine in your edition, `npm install @pattern-lab/engine-handlebars` should do the trick.
3+
To install the Handlebars PatternEngine in your edition, `npm install --save @pattern-lab/engine-handlebars` should do the trick.
44

55
## Supported features
66

@@ -11,3 +11,34 @@ To install the Handlebars PatternEngine in your edition, `npm install @pattern-l
1111
* [x] [Pattern States](http://patternlab.io/docs/pattern-states.html)
1212
* [ ] [Pattern Parameters](http://patternlab.io/docs/pattern-parameters.html) (Accomplished instead using [native Handlebars partial arguments](http://handlebarsjs.com/partials.html))
1313
* [ ] [Style Modifiers](http://patternlab.io/docs/pattern-stylemodifier.html) (Accomplished instead using [native Handlebars partial arguments](http://handlebarsjs.com/partials.html))
14+
15+
## Helpers
16+
17+
To add custom [helpers](http://handlebarsjs.com/#helpers) or otherwise interact with Handlebars directly, create a file named `patternlab-handlebars-config.js` in the root of your Pattern Lab project, or override the default location by specifying one or several glob patterns in the Pattern Lab config:
18+
19+
```json
20+
{
21+
...
22+
"engines": {
23+
"handlebars": {
24+
"helpers": [
25+
"handlebars-helpers.js",
26+
"helpers/**/*.js"
27+
]
28+
}
29+
}
30+
}
31+
```
32+
33+
Each file should export a function which takes Handlebars as an argument.
34+
35+
```js
36+
module.exports = function(Handlebars) {
37+
// Put helpers here
38+
39+
Handlebars.registerHelper('fullName', function(person) {
40+
// Example: person = {firstName: "Alan", lastName: "Johnson"}
41+
return person.firstName + " " + person.lastName;
42+
});
43+
};
44+
```

0 commit comments

Comments
 (0)