2022.2

Table Of Contents
Let'ssayyouwanttocreateacustomHelperthatreturnsthecurrentdate.ThenameoftheHelper
shouldbetoday,sothatitcanbeusedinanexpressionasfollows:
Example: {{today}}
Here'showyoudothat.
1. OntheScriptspane,clicktheblacktrianglenexttotheNewbuttonandclickControl Script.
ControlScriptsareexecutedfirst.See"ControlScripts"onpage838and"Thescriptflow:when
scriptsrun"onpage824.
2. EnteranameforthescriptintheNamefield.ThisnamewillappearontheScriptspane.It
doesn'thavetobethesameasthenameoftheHelperthatcanbeusedinexpressions.OneCon-
trolScriptcanregistermultipleHelpers.
3. WritecodethatregisterstheHelper,usingtheHandlebars.registerHelper(name,
helper)function.
l
nameisthenameoftheHelperbywhichitshouldbecalledinexpressions.Putthenamein
quotes.
l
helperisthecodethatshouldrunwhentheHelperiscalledfromanexpression.
Hereisanexample:
Handlebars.registerHelper('today', function() {
return new Date();
});
4. ClickOK.ThenewscriptappearsontheScriptspaneintheControl Scriptsfolder.
NowthattheHelperisregistered,theexpression{{today}}inatemplatewillreturnthecurrentdate.
InthesameexpressionyoucoulduseaHelperthatformatsthedate.Forexample:{{dateLong today}}
willformatthecurrentdateasalongdate,e.g.February23,2022.(ForalistofFormatHelpers,see
"FormatHelpers"onpage769.)
Ifyou'dliketoformatthevalueinthescriptitself,youcanusethefunctionsprovidedbytheformatter
objectinstandardDesignerscripts;see"formatter"onpage1175.
Forexample,thiscoderegistersaHelperthatformatstheoutputasa'medium'date.
Handlebars.registerHelper('today', function () {
let today = new Date();
return formatter.dateMedium( today )
})
Page 772