Helpers
The user can register helpers with the Handlebars runtime A mustache-statement with a single id is interpreted as helper call.
07-helpers/helper-without-args.hb-spec.json
A helper without args
{{help}}
{
"type": "Program",
"body": [
{
"type": "MustacheStatement",
"escaped": true,
"params": [],
"path": {
"type": "PathExpression",
"original": "help",
"data": false,
"depth": 0,
"parts": ["help"],
"loc": {
"start": { "line": 1, "column": 2 },
"end": { "line": 1, "column": 6 }
}
},
"strip": { "open": false, "close": false },
"loc": {
"start": { "line": 1, "column": 0 },
"end": { "line": 1, "column": 8 }
}
}
],
"strip": {},
"loc": {
"start": { "line": 1, "column": 0 },
"end": { "line": 1, "column": 8 }
}
}
If a helper-name and an input property have the same value, the helper is chosen.
07-helpers/helpers-have-precedence-over-input-props.hb-spec.json
Helpers have precedence over input properties
{{help}}
{
"type": "Program",
"body": [
{
"type": "MustacheStatement",
"escaped": true,
"params": [],
"path": {
"type": "PathExpression",
"original": "help",
"data": false,
"depth": 0,
"parts": ["help"],
"loc": {
"start": { "line": 1, "column": 2 },
"end": { "line": 1, "column": 6 }
}
},
"strip": { "open": false, "close": false },
"loc": {
"start": { "line": 1, "column": 0 },
"end": { "line": 1, "column": 8 }
}
}
],
"strip": {},
"loc": {
"start": { "line": 1, "column": 0 },
"end": { "line": 1, "column": 8 }
}
}
Helper parameters
A mustache can be a helper call with space-separated parameters. Each parameter is a PathExpression or a Literal expression
HelperParameters
MustacheParameters ::
Whitespace MustacheParameter MustacheParametersopt
MustacheParameter ::
Literal
PathExpression
SubExpression
07-helpers/helper-with-args.hb-spec.json
A helper with string-args
{{help first second}}
{ "first": "hello", "second": "world" }
helloworld
{
"type": "Program",
"body": [
{
"type": "MustacheStatement",
"escaped": true,
"params": [
{
"type": "PathExpression",
"original": "first",
"data": false,
"depth": 0,
"parts": ["first"],
"loc": {
"start": { "line": 1, "column": 7 },
"end": { "line": 1, "column": 12 }
}
},
{
"type": "PathExpression",
"original": "second",
"data": false,
"depth": 0,
"parts": ["second"],
"loc": {
"start": { "line": 1, "column": 13 },
"end": { "line": 1, "column": 19 }
}
}
],
"path": {
"type": "PathExpression",
"original": "help",
"data": false,
"depth": 0,
"parts": ["help"],
"loc": {
"start": { "line": 1, "column": 2 },
"end": { "line": 1, "column": 6 }
}
},
"strip": { "open": false, "close": false },
"loc": {
"start": { "line": 1, "column": 0 },
"end": { "line": 1, "column": 21 }
}
}
],
"strip": {},
"loc": {
"start": { "line": 1, "column": 0 },
"end": { "line": 1, "column": 21 }
}
}