Handlebars

Commonly used Handlebar Tokens

Tokens

{{Name}} Name of a property in your schema
{{ @index}} Index of the Item inside an {{#each Items}} list
{{ @first}} is the item the first item inside an {{#each Items}} list
{{ @last}} is the item the last item inside an {{#each Items}} list
{{Context.ModuleId}} Current Module ID
{{Context.ModuleTitle}} Current Modules Title
{{Context.PortalId }} Current Portal ID
{{Settings.Name}} Reference to a setting

{{../Name}}: Name of a property one level up the tree (you use this when you want to address a "root" property when inside a list of Items using {{#each Items}}

Advanced:
{{Schema.properties.xxx}} Reference to a property in your Schema

Serverside Handlebars Helpers

HelperBlock HelperparametersOutputExample
equalYes2 strings{{#equal Title "Text"}}
....
{{else}}
...
{{/equal}}
multiplyNo2 numbersnumber{{multiply SettingsColumns 2}}
divideNo2 numbersnumber{{divide SettingsColumns 2}}
addNo2 numbersnumber{{add @index 1}}
substractNo2 numbersnumber{{substract Settings.Columns 1}}
publishedYesarray
registerscriptNojavascript fileNothing{{registerscript "js/script.js"}}
registerstylesheetNocss fileNothing{{registerstylesheet "css/style.css"}}
registerservicesframeworkNoNoNothing
arrayindexNo
arraytranslateNo
formatNumberNo.net format , culture (or invariant)string
formatDateTimeNo.net format , culture (or invariant)string{{formatDateTime DateField "dd/MMM/yy" "nl-NL" }}
ifandYesmultiple variables to check{{#ifand Title Summary}}
....
{{else}}
...
{{/ifand}}
iforYesmultiple variables to check{{#ifor Title Summary}}
....
{{else}}
...
{{/ifor}}
convertHtmlToTextNotextstring{{convertHtmlToText Description}}
replacenewlineNofield, textstring{{replacenewline Title "<br>"}}
replaceNofiled, string, stringstring{{replace Title "x" "y"}}
truncateWords
(from version 3.1.2)
Notext, maxCharacters, trailingTextstring{{truncateWords Description 50 "..."}}
convertToJson
(from version 3.2)
Noany variablestring{{convertToJson article}}
protectemailNoemail, subject, visible textstring{{protectemail "[email protected]" "subject" "email"}}
rawYes{{{{raw}}}}
...
{{{{/raw}}}}
containsYesvariable, text to check{{#contains Title "hello"}}
....
{{else}}
...
{{/contains}}
prefixurlNoWill convert a url to the appropriate href (based on a regular expression).
Types supported: link (adds http(s), tel and email.
stringurl

Clientside Handlebars Helpers

Need to be added by yourself to a javascript file. More info

Most of the times, only used in item template of multi document templates like articles.

if (typeof Handlebars != 'undefined') {
        Handlebars.registerHelper('formatDateTime', function (context, format) {

            if (window.moment && context && moment(context).isValid()) {

                var f = format || "DD/MM/YYYY";

                return moment(context).format(f);

            } else {

                return context;   //  moment plugin is not available, context does not have a truthy value, or context is not a valid date

            }

        });

       
    }