Templates
Cloud CMS supports the usage of templates at various points to generate presentation and output for things like emails, PDFs, web page components and more.
Cloud CMS supports two template engines - Handlebars and Freemarker. In general, we recommend using Handlebars since the syntax is a bit easier. This document covers Handlebars and describes helper functions available in Handlebars that make processing simpler.
Model Variables
The following describes the internal structure of model variables based on their type.
Workflow
Property | Type | Description |
---|---|---|
id | string | The ID of the workflow instance |
modelId | string | The ID of the workflow model for this instance |
modelVersion | number | The version of the workflow model for this instance |
state | string | The state of the workflow - one of the following: NOT_STARTED, RUNNING, SUSPENDED, TERMINATED |
timeStarted | calendar | The time the workflow was started |
timeCompleted | calendar | The time the workflow was completed (if completed) |
context | object | Contextual variables being passed along with the workflow |
workflowData | object | Data being passed along with the workflow |
swimlaneIds | array | The IDs of any swimlanes defined within the workflow |
runtime.applicationId | string | Optional ID of the Application this workflow is running against |
runtime.emailProviderId | string | Optional ID of the Email provider this workflow is using for email dispatches |
runtime.repositoryId | string | Optional ID of the Repository this workflow uses for content and templates |
runtime.branchId | string | Optional ID of the Repository branch this workflow uses for content and templates |
projectId | string | Optional ID of a project that this workflow is attached to |
projectTitle | string | Optional Title of a project that this workflow is attached to |
resourceUrl | string | The API URL of the workflow instance |
adminUrl | string | The Administrative Console URL for this workflow instance |
url | string | The Cloud CMS URL for this workflow instance |
tenantUrl | string | The URL to the Cloud CMS user interface |
contentUrl | string | The URL to the base content path for the content in this workflow instance |
Example:
The workflow <a href="{{ workflow.url }}">{{ workflow.title }}</a> was started on {{ workflow.timeStarted}}
and completed on {{ workflow.timeCompleted }}.
Workflow Task
Property | Type | Description |
---|---|---|
id | string | The ID of the workflow task |
title | string | The title of the workflow task |
description | string | The description of the workflow task |
timeStarted | calendar | The time the workflow was started |
timeCompleted | calendar | The time the workflow was completed (if completed) |
context | object | Contextual variables being passed along with the workflow task |
workflowData | object | Data being passed along with the workflow task |
workflowId | string | The ID of the workflow instance |
workflowTitle | string | The title of the workflow instance |
workflowDescription | string | The description of the workflow instance |
projectId | string | Optional ID of a project that this workflow is attached to |
projectTitle | string | Optional Title of a project that this workflow is attached to |
assigneeId | string | The ID of the assignee |
assigneeName | string | The name of the assignee |
assigneeEmail | string | The email of the assignee |
resourceUrl | string | The API URL of the workflow task |
adminUrl | string | The Administrative Console URL for this workflow task |
url | string | The Cloud CMS URL for this workflow task |
tenantUrl | string | The URL to the Cloud CMS user task |
contentUrl | string | The URL to the base content path for the content in this workflow task |
Example:
The workflow task <a href="{{ workflowTask.url }}">{{ workflowTask.title }}</a> has been assigned
to {{ workflowTask.assigneeName }} ({{ workflowTask.assigneeEmail }}) within project '{{ workflowTask.projectTitle }}'.
Workflow Transition
Property | Description |
---|---|
id | The ID of the route that was fired |
fromNodeId | The ID of the node from which the transition starts |
toNodeId | The ID of the node to which the transition ends |
Example:
The workflow is transitioning from node {{ transition.fromNodeId }} to node {{transition.toNodeId}}
via route {{transition.id}}.
Helper Functions
each
Allows for iteration of a list of items.
Syntax:
{{each array}}
Example - assume we have the following content:
{
"title": "My Article",
"description": My Article Description",
"tags": ["tag1", "tag2"]
}
And the following template:
Title: {{title}}
<br/>
Description: {{description}}
<br/>
{{#each tags}}
Tag: {{this}}
<br/>
{{/each}}
This will render:
Title: My Article
Description: My Article Description
Tag: tag1
Tag: tag2
if
Conditionally executes a block.
Syntax:
{{#if boolean}}
this shows if true
{{/if}}
Example - assume we have the following:
{
"_doc": "GUID1",
"title": "My Article",
"description": My Article Description",
"download": true
}
And the following template:
Title: {{title}}
<br/>
Description: {{description}}
<br/>
{{#if download}}
<a href="/download/{{_doc}}.txt">Download</a>
{{/if}}
This will render:
Title: My Article
Description: My Article Description
Download
unless
Conditionally executes a block.
Syntax:
{{#unless boolean}}
this shows if false
{{/unless}}
Example - assume we have the following:
{
"_doc": "GUID1",
"title": "My Article",
"description": My Article Description",
"preventDownload": false
}
And the following template:
Title: {{title}}
<br/>
Description: {{description}}
<br/>
{{#unless preventDownload}}
<a href="/download/{{_doc}}.txt">Download</a>
{{/unless}}
This will render:
Title: My Article
Description: My Article Description
Download
capitalizeFirst
Capitalizes the first letter of a given value.
Syntax:
{{capitalizeFirst text}}
Example - assume we have the following:
{
"title": "my article"
}
And the following template:
Title: {{capitalizeFirst title}}
This will render:
Title: My article
center
Centers the value in a field of a given width.
Syntax:
{{center text}}
Example - assume we have the following:
{
"title": "my article"
}
And the following template:
Title: --{{center title size=20 pad=" "}}--
This will render:
Title: -- my article --
Note that "my article" has a length of 10.
The displayed value has a length of 20 with padding of 5 spaces on either side.
cut
Removes all values of arg from the given string.
Syntax:
{{cut text textToCut}}
Example - assume we have the following:
{
"title": "my article"
}
And the following template:
Title: {{cut title " "}}
This will render:
Title: myarticle
defaultIfEmpty
Emits the given default if the value is empty.
Syntax:
{{defaultIfEmpty value textIfEmpty}}
Example - assume we have the following:
{
"title": ""
}
And the following template:
Title: {{defaultIfEmpty title "nothing to see here"}}
This will render:
Title: nothing to see here
join
Joins multiple string fragments together.
Syntax:
{{join value1 value2 value3 ... valueN joinText}}
Example - assume we have the following:
{
"path": "/folder1/folder2",
"subfolder": "folder3",
"filename": "myfile.txt"
}
And the following template:
Path: {{join path subfolder filename "/"}}
This will render:
Path: /folder1/folder2/folder3/myfile.txt
ljust
Applies left-side padding to a string to increase it to a given length.
Syntax:
{{ljust text size pad}}
Example - assume we have the following:
{
"title": "my article"
}
And the following template:
Title: --{{ljust title size=20 pad=" "}}--
This will render:
Title: --my article --
rjust
Applies right-side padding to a string to increase it to a given length.
Syntax:
{{rjust text size pad}}
Example - assume we have the following:
{
"title": "my article"
}
And the following template:
Title: --{{rjust title size=20 pad=" "}}--
This will render:
Title: -- my article--
substring
Returns a new string that is a substring of a given value.
Syntax:
{{substring value startIndex [endIndex]}}
Example - assume we have the following:
{
"title": "my article"
}
And the following template:
Title: {{substring title 0 2}}
This will render:
Title: my
lower
Returns a new string that is the lowercase representation of a given value.
Syntax:
{{lower value}}
Example - assume we have the following:
{
"title": "My Article"
}
And the following template:
Title: {{lower title}}
This will render:
Title: my article
upper
Returns a new string that is the uppercase representation of a given value.
Syntax:
{{upper value}}
Example - assume we have the following:
{
"title": "My Article"
}
And the following template:
Title: {{upper title}}
This will render:
Title: MY ARTICLE
slugify
Returns a new string that is the "slugified" version of a given value. The slugified value is lowercase, has all non-word characters removed (non-alphanumerics), has spaces converted to hyphens and has leadining and trailing whitespace removed.
Syntax:
{{slugify value}}
Example - assume we have the following:
{
"_doc": "GUID1",
"title": "My Article",
"body": "...",
"seo": "My Article on Quantum Physics"
}
And the following template:
<a href="/article/view/{{_doc}}/{{seo}}>View Article</a>
This will render:
<a href="/article/view/GUID1/my-article-on-quantum-physics">View Article</a>
stringFormat
Formats the variable according to the argument, a string formatting specifier.
Syntax:
{{stringFormat string param0 param1 ... paramN}}
Example - assume we have the following:
{
"title": "My Article",
"author": "Joe Smith",
"email": "joe@smith.com"
}
And the following template:
{{stringFormat "%s by %s (%s)" title author email}}
This will render:
My Article by Joe Smith (joe@smith.com)
stripTags
Strips XML from the given value.
Syntax:
{{stripTags value}}
Example - assume we have the following:
{
"title": "My Article <b>is awesome</b>"
}
And the following template:
{{stripTags title}}
This will render:
My Article is awesome
capitalize
Capitalizes all the whitespace separated words in a String.
Syntax:
{{capitalize value}}
Example - assume we have the following:
{
"title": "hello my friend, welcome to the machine"
}
And the following template:
{{capitalize title}}
This will render:
Hello My Friend, Welcome To The Machine
abbreviate
Truncates a string if it is longer than the specified number of characters. Truncated strings will end with a translatable ellipsis sequence ("...").
Syntax:
{{abbreviate value maxLength}}
Example - assume we have the following:
{
"title": "hello my friend, welcome to the machine"
}
And the following template:
{{abbreviate title 15}}
This will render:
hello my friend...
replace
Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence.
Syntax:
{{replace value original replacement}}
Example - assume we have the following:
{
"title": "hello my friend, welcome to the machine"
}
And the following template:
{{replace title "friend" "son"}}
This will render:
hello my son, welcome to the machine
dateFormat
Formats a date into a display-friendly string.
Syntax:
{{dateFormat date format}}
Format parameters is one of:
- "full": full date format. For example: Tuesday, June 19, 2012
- "long": long date format. For example: June 19, 2012
- "medium": medium date format. For example: Jun 19, 2012
- "short": short date format. For example: 6/19/12
- "pattern": a date pattern.
Otherwise, the default formatter will be used.
Example - assume we have the following:
{
"title": "My Article",
"_system": {
"created_on": {
}
}
}
And the following template:
{{title}} published on {{dateFormat _system.created_on.ms "full"}}
This will render:
My Article published on Tuesday, June 19, 2012
numberFormat
Formats a number into a display-friendly string.
Syntax:
{{numberFormat number format}}
Format parameters is one of:
- "integer": the integer number format
- "percent": the percent number format
- "currency": the decimal number format
- "pattern": a decimal pattern.
Otherwise, the default formatter will be used.
More options:
- groupingUsed: Set whether or not grouping will be used in this format.
- maximumFractionDigits: Sets the maximum number of digits allowed in the fraction portion of a number
- maximumIntegerDigits: Sets the maximum number of digits allowed in the integer portion of a number
- minimumFractionDigits: Sets the minimum number of digits allowed in the fraction portion of a number
- minimumIntegerDigits: Sets the minimum number of digits allowed in the integer portion of a number
- parseIntegerOnly: Sets whether or not numbers should be parsed as integers only
- roundingMode: Sets the {@link java.math.RoundingMode} used in this NumberFormat.
Example - assume we have the following:
{
"title": "ColecoVision Corporation",
"index": "NASDAQ",
"price": 10.5712
}
And the following template:
{{title}} is trading at {{numberFormat price "currency" maximumFractionDigits=2}}
This will render:
ColecoVision Corporation is trading at $10.57
now
Formats a number into a display-friendly string.
Syntax:
{{now format}}
Format parameters is one of:
- "full": full date format. For example: Tuesday, June 19, 2012
- "long": long date format. For example: June 19, 2012
- "medium": medium date format. For example: Jun 19, 2012
- "short": short date format. For example: 6/19/12
- "pattern": a date pattern
Example - assume we have the following:
{
"title": "ColecoVision Corporation",
"index": "NASDAQ",
"price": 10.5712
}
And the following template:
{{title}} is trading at {{numberFormat price "currency" maximumFractionDigits=2}} on {{now "full"}}.
This will render:
ColecoVision Corporation is trading at $10.57 on Friday, August 28, 2015.