2022.2

Table Of Contents
Note: ThereareafewdifferencesbetweentheofficialHandlebarslibraryandOLConnect.InOL
Connect:
l
TheblockHelperMissingandhelperMissinghooksarenotimplemented.
l
Passingoptions.hash,options.helpersandoptions.partialsargumentstoHelpersisnot
supported.(options.data,options.fnandoptions.inversearesupported.)
l
RegisteringmultipleHelperswithasinglecalltoHandlebars.registerHelper()isnotsup-
ported.
ExamplesofcustomHelpers
Coloring a negative value
Valuesinyourdatacouldbepositiveornegative.Let'ssayyouwantaHelperthatcolorsanynegative
valuesred.Here'sthecodeforsuchaHelper.
Handlebars.registerHelper('highlightNegative', function ( value ) {
let result = value
if( -1 === Math.sign(value) ) {
result = '<span style="color:red">' + value + '</span>';
}
return new Handlebars.SafeString(result);
})
ThenameoftheHelperishighlightNegative.TheHelpercheckswhetherthevaluethatitgetspassed
byanexpressionisnegative,usingaJavaScriptfunction:Math.sign()(seethedocumentationofMoz-
illa).Ifitis,itwrapsthevalueinaSpanwithastyleattributethathassomeCSStocolorthevaluered.
Onceyou'veaddedthisHelper,itcanbeusedinanyexpressionthatreturnsanumbervalue.
Example: {{highlightNegativeTotal}}
ThisexpressioncallstheHelperwiththenameofadatafield,Total,thathasanumber.Ifthevalueof
thedatafieldis-15,theoutputofthisexpressionwillbe-15.
Inserting a hyperlink
Let'sassumeyouhavehyperlinksinyourdataaswellastextstouseaslabelforthehyperlinks.For
example:
[
{
"url": "http://www.nu.nl",
"label": "nu.nl"
Page 773