Hash arguments

Hash arguments allow named arguments to be passed to a Helper or partial. They are particularly useful if you want to pass a variable number of parameters to a Helper or partial, or to pass data from the main record to a Helper in a Dynamic Table, for example.

Passing hash arguments

The syntax of a hash argument is: <literal>=<expression>.

Note: Whitespace around the “=” is not allowed: parameter=value is valid, but parameter = value is not.

The following expression passes an argument named 'test' with a value of '123', to a Helper named 'foo':

{{foo test=123}}

Since the part after the "=" is an expression, you could pass a data field to make the Helper or partial use the value of that data field.

{{foo test=myField}}

In the expression you can access data at different levels, like in any expression.

{{foo test=../fieldName}}

The above expression navigates one level up from the data with which the expression is resolved. This works in Dynamic Tables, because expressions in a Dynamic Table are resolved using the detail record associated with the nearest table row, rather than using the main record. See also: Data in expressions.

Accessing hash arguments in a Helper

A helper can access hash arguments through options.hash. If a Helper is registered with options as the last parameter, the options object is automatically passed to the Helper when it is called. For example:

Copy
Handlebars.registerHelper("foo", function(options) {
    logger.info(options.hash.test);
})

This Helper logs the value of a hash argument called test
When called with the expression {{foo test=123}}, it is expected to log "123".

See devdocs.io: Hash arguments for documentation on this feature in the original Handlebars library.

Accessing hash arguments in partials

Hash arguments passed to a partial are added to the current scope, in other words, to the data the partial has access to. Since partials are Handlebars templates, they access that data via expressions.

For example, this expression in a section includes a partial called "myPartial.hbs", setting the value of test to 123:

{{+myPartial test=123}}

Now, if the partial contains the expression: {{test}}, that expression will be replaced with “123”.

Note: Hash arguments overwrite any existing properties with the same name.

See devdocs.io: Partial parameters for documentation on this feature in the original Handlebars library.