2022.1

Table Of Contents
Examples of custom helpers
Date
The following code registers a function that returns the current date.
Handlebars.registerHelper('now', function() { return new Date();
});
After the helper is registered, the expression {{dateLong now}} in a Handlebars template will
return the current date, formatted as a long date, e.g. February 23, 2022.
Get coverage
This helper returns an object whose properties are filled with values based on data fields in the
current context (this). For example, when called within an #each block that is executed with
the records of a detail table, this refers to the current detail table record. (See also: "#with and
#each" on page454.)
Handlebars.registerHelper('getObjectAndCoverage', function () {
let coverage = this.O_L99042;
let category = this.C_L99042
if( category === 'extra' ) {
coverage = 'Extra + glass';
}
return {
"object": "Residential building",
"amount": this.L10039D,
"coverage": coverage,
"premium" : this.L10145
}
})
HTML-escaping in a helper
If a helper needs to HTML-escape a string you can call Handlebars.escapeHTML() in that
function.
For example, if you would want to HTML-escape the value of this.field, but not "<p>" or
"</p>", you could write:
function() { return "<p>" + Handlebars.escapeHTML(this.field) + "</p>"; }
In the original Handlebars library this function is called Handlebars.escapeExpression().
Page 456