---
agentTools:
  projectIndex: https://opencontent.readme.io/v3.5/llms.txt
---

# Handlebars

Commonly used Handlebar Tokens

[block:api-header]
{
  "type": "basic",
  "title": "Tokens"
}
[/block]

{{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

[block:api-header]
{
  "type": "basic",
  "title": "Serverside Handlebars Helpers"
}
[/block]

[block:parameters]
{
  "data": {
    "h-0": "Helper",
    "h-1": "Block Helper",
    "h-2": "parameters",
    "0-0": "equal",
    "0-1": "Yes",
    "0-2": "2 strings",
    "h-3": "Output",
    "h-4": "Example",
    "0-4": "{{#equal Title \"Text\"}}\n....\n{{else}}\n...\n{{/equal}}",
    "1-0": "multiply",
    "2-0": "divide",
    "5-0": "published",
    "6-0": "registerscript",
    "7-0": "registerstylesheet",
    "8-0": "arrayindex",
    "9-0": "arraytranslate",
    "10-0": "formatNumber",
    "11-0": "formatDateTime",
    "12-0": "ifand",
    "1-1": "No",
    "1-2": "2 numbers",
    "1-3": "number",
    "2-1": "No",
    "2-2": "2 numbers",
    "2-3": "number",
    "5-1": "Yes",
    "5-2": "array",
    "6-1": "No",
    "6-2": "javascript file",
    "7-2": "css file",
    "12-2": "multiple variables to check",
    "11-2": "[.net format](https://msdn.microsoft.com/en-US/library/8kb3ddd4.aspx) , culture (or invariant)",
    "10-2": ".net format , culture (or invariant)",
    "10-1": "No",
    "11-1": "No",
    "10-3": "string",
    "11-3": "string",
    "6-3": "Nothing",
    "7-3": "Nothing",
    "7-1": "No",
    "8-1": "NO",
    "9-1": "No",
    "12-1": "Yes",
    "11-4": "{{formatDateTime DateField \"dd/MMM/yy\" \"nl-NL\" }}",
    "3-0": "add",
    "3-1": "No",
    "3-2": "2 numbers",
    "4-0": "substract",
    "4-1": "No",
    "4-2": "2 numbers",
    "3-3": "number",
    "4-3": "number",
    "3-4": "{{add @index 1}}",
    "4-4": "{{substract Settings.Columns 1}}",
    "1-4": "{{multiply SettingsColumns 2}}",
    "2-4": "{{divide SettingsColumns 2}}",
    "15-0": "truncateWords\n(from version 3.1.2)",
    "15-1": "No",
    "15-2": "text, maxCharacters, trailingText",
    "15-3": "string",
    "15-4": "{{truncateWords Description 50 \"...\"}}",
    "14-0": "convertHtmlToText",
    "14-1": "No",
    "14-2": "text",
    "14-3": "string",
    "14-4": "{{convertHtmlToText Description}}",
    "16-0": "convertToJson\n(from version 3.2)",
    "16-1": "No",
    "16-2": "any variable",
    "16-3": "string",
    "16-4": "{{convertToJson article}}",
    "13-0": "ifor",
    "13-1": "Yes",
    "13-2": "multiple variables to check",
    "12-4": "{{#ifand Title Summary}}\n....\n{{else}}\n...\n{{/ifand}}",
    "13-4": "{{#ifor Title Summary}}\n....\n{{else}}\n...\n{{/ifor}}",
    "6-4": "{{registerscript \"js/script.js\"}}",
    "7-4": "{{registerstylesheet  \"css/style.css\"}}"
  },
  "cols": 5,
  "rows": 17
}
[/block]

[block:api-header]
{
  "type": "basic",
  "title": "Clientside Handlebars Helpers"
}
[/block]

Need to be added by yourself to to a javascript file. [More info](http://handlebarsjs.com/)

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

[block:code]
{
  "codes": [
    {
      "code": "if (typeof Handlebars != 'undefined') {\n        Handlebars.registerHelper('formatDateTime', function (context, format) {\n\n            if (window.moment && context && moment(context).isValid()) {\n\n                var f = format || \"DD/MM/YYYY\";\n\n                return moment(context).format(f);\n\n            } else {\n\n                return context;   //  moment plugin is not available, context does not have a truthy value, or context is not a valid date\n\n            }\n\n        });\n\n       \n    }",
      "language": "javascript",
      "name": "Exemple "
    }
  ]
}
[/block]