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
Helper | Block Helper | parameters | Output | Example |
---|---|---|---|---|
equal | Yes | 2 strings | {{#equal Title "Text"}} .... {{else}} ... {{/equal}} | |
multiply | No | 2 numbers | number | {{multiply SettingsColumns 2}} |
divide | No | 2 numbers | number | {{divide SettingsColumns 2}} |
add | No | 2 numbers | number | {{add @index 1}} |
substract | No | 2 numbers | number | {{substract Settings.Columns 1}} |
published | Yes | array | ||
registerscript | No | javascript file | Nothing | {{registerscript "js/script.js"}} |
registerstylesheet | No | css file | Nothing | {{registerstylesheet "css/style.css"}} |
arrayindex | NO | |||
arraytranslate | No | |||
formatNumber | No | .net format , culture (or invariant) | string | |
formatDateTime | No | .net format , culture (or invariant) | string | {{formatDateTime DateField "dd/MMM/yy" "nl-NL" }} |
ifand | Yes | multiple variables to check | {{#ifand Title Summary}} .... {{else}} ... {{/ifand}} | |
ifor | Yes | multiple variables to check | {{#ifor Title Summary}} .... {{else}} ... {{/ifor}} | |
convertHtmlToText | No | text | string | {{convertHtmlToText Description}} |
truncateWords (from version 3.1.2) | No | text, maxCharacters, trailingText | string | {{truncateWords Description 50 "..."}} |
convertToJson (from version 3.2) | No | any variable | string | {{convertToJson article}} |
Clientside Handlebars Helpers
Need to be added by yourself to 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
}
});
}
Updated over 6 years ago