Data Templates¶
Data templates in Emakin transform data models into various output formats, such as text or HTML. These templates are utilized across different Emakin components, including form controls and email templates. Templates utilize XPath queries embedded within double curly braces {{
and }}
.
For instance, given a data model field named "username," a basic template would be:
1 |
|
If the "username" field contains "Madonna," the rendered output would be:
1 |
|
All XML values are inherently treated as strings; therefore, no automatic data type formatting is performed. To format numbers or dates, explicit type conversion or formatting functions are necessary.
Culture Support¶
Data templates are culture-sensitive, adapting formatting based on the specified culture. The culture is typically derived from user preferences, but can be explicitly set. If no culture is specified, the invariant culture is used.
Specifying Culture in Scripting¶
The following JavaScript example demonstrates formatting using a specific culture ('tr-TR' - Turkish):
1 2 3 4 5 |
|
Data Type Formatting¶
Text Formatting¶
Text or string values are rendered without any implicit formatting.
Number Formatting¶
While functions like "Sum" and "Count" return numbers directly, the number()
function can be used for explicit type conversion if needed. Number values are formatted according to decimal rules by default.
Examples:
Template | Outputs | Culture |
---|---|---|
{{ 12345678912345 }} | 12345678912345 | |
{{ 123456.78912345 }} | 123456.78912345 | |
{{ number(123456.78912345678912345) }} | 123456.789123457 | |
{{ format( number(123456.789) ) }} | 123456.789 | |
{{ format( number(123456789) ) }} | 123456789 | |
{{ format( number(123456789), 'n') }} | 123,456,789.00 | |
{{ format( number(123456789), 'n') }} | 123.456.789,00 | tr-TR |
{{ format( number(123456789), 'n0') }} | 123,456,789 | |
{{ format(number(123456789), 'c') }} | 123.456.789,00 ₺ | tr-TR |
Date Formatting¶
The template system automatically recognizes XML date types formatted as "YYYY-MM-DDTHH:MM:SSTZ." Emakin consistently uses this format for date values in its data model. Dates in other formats are treated as strings.
Examples (assuming MyDate
contains 2014-01-31T09:00:00+02:00
):
Template | Outputs | Culture |
---|---|---|
{{ MyDate }} | 01/31/2014 16:04:12 +02:00 | |
{{ format(MyDate,'dd/MM/yyyy') }} | 31/01/2014 | |
{{ format(MyDate) }} | 31.1.2014 09:00 | tr-TR |
{{ format(MyDate,'d') }} | 31/01/2014 | |
{{ format(MyDate,'D') }} | Monday, June 15, 2009 | en-US |
{{ format(MyDate,'o') }} | <br>2014-01-31T09:00:00+02:00<br> |
Scripting example¶
1 2 3 4 |
|
Scripting example¶
A way to remove time from date node:
1 2 3 4 |
|
format()
Function Options¶
The format()
function offers various options for customizing the output. See the table below for details. Note that the available options and their behavior might vary based on the data type.
Data Type | Format Option | Description | Sample Data | Output |
---|---|---|---|---|
String | Print string as automatically detection | <script>alert('hello')</script><div>hello</div> | <div>hello</div> | |
String | Print string as automatically detection | 12.345 | 12.3 | |
String | Print string as automatically detection | 12 | 12 | |
String | Print string as automatically detection | 2022-05-07T00:00:00+03:00 | 07.05.2022 00:00 | |
String | Print string as automatically detection | True / true | ✓ (U+2713) | |
String | Print string as automatically detection | False / false | ✕ (U+2715) | |
String | html | Print string as encoded html text | <script>alert('hello')</script><div>hello</div> | <script>alert('hello')</script><div>hello</div> |
String | safe | Print value as safe html with discarding dangerous tags | <script>alert('hello')</script><div>hello</div> | <div>hello</div> |
String | string | Print string without any encoding applied | <script>alert('hello')</script><div>hello</div> | <script>alert('hello')</script><div>hello</div> |
Number | n0 | Print number as integer without any decimal | 12.345 | 12 |
Number | n1 | Print number as decimal with 1 number after dot | 12.345 | 12.3 |
Boolean | Print value as unicode check mark | True / true | ✓ (U+2713) | |
Boolean | Print value as unicode check mark | False / false | ✕ (U+2715) | |
DateTime | Print date value in user's locale preference | 2022-05-07T00:00:00+03:00 | 07.05.2022 00:00 | |
DateTime | o | Print date in ISO format | 2022-05-07T00:00:00+03:00 | 2022-05-07T00:00:00+03:00 |
DateTime | m | Print date in dynamic formatted format | 2022-05-07T00:00:00+03:00 | 2 days ago |
DateTime | dd/MM/yyyy | Print date in specified date format | 2022-05-07T00:00:00+03:00 | 07/05/2022 |
Conditional Formatting¶
Conditional rendering is achieved using the following syntax:
1 2 |
|
Example:
Basic usage
1 |
|
Basic usage with else clause
1 |
|
Repeating Templates¶
To apply a template to multiple nodes, use this syntax:
1 |
|
This iterates over each element matching ItemXPath
and applies the template.
Example:
1 2 3 4 5 6 7 8 9 10 |
|
Generates the following output:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Repeating with attribute¶
The x-repeat
attribute provides an alternative to the =>
syntax for repeating templates, particularly useful for HTML generation where the =>
syntax might lead to tag corruption. For example:
1 2 3 4 5 6 7 |
|
This attribute can be used with any element. For example, it can also be used with "li" tag.
1 2 3 4 5 6 |
|
Recursive Repeating Templates¶
For recursive repetition, use this syntax:
1 |
|
The template is applied recursively to the results of each iteration.
Example:
1 2 3 4 5 |
|
result:
1 2 3 4 5 |
|
Template Variables¶
Both custom process variables and system properties are available within templates. Client-side and server-side scripts have different variable contexts.
Client-Side Template Variables¶
Available in client-side scripts (e.g., form scripts):
Variable Name | Description |
---|---|
$staticUrl | Base URL for static resources. Static resources base address. (ex: https://static.emakin.com/ ) |
$applicationUrl | Base URL for the application. (ex: https://mydomain.emakin.com/app/ ) |
$Process | Unique id of the current process |
$FolderName | Name of the folder containing the process |
$CustomVariable | Custom variables defined within the process |
Server-Side Template Variables¶
Available in server-side scripts (e.g., pre/post-work scripts):
Variable Name | Description |
---|---|
$ApplicationName | Name of an application. (ex: emakin.com ) |
$ApplicationUrl | Base URL of the application |
$Domain.Name | Name of the domain |
$Domain.Url | URL of the domain |
$Domain.LogoUrl | URL of the domain logo |
$CustomVariable | Custom variables defined within the process |
Specific Template Variable Contexts¶
Activity Notifications: In addition to server-side variables, activity notifications use:
Variable Name | Description |
---|---|
$Id | Id number of a work item |
$WorkItem | WorkItem object (access properties using dot notation, e.g., $WorkItem.Instance.Number ) |
$Recipients | Comma-separated recipient names |
$Url | Url of a work item. (ex: https://mydomain.emakin.com/app/?/workitem=1234 ) |
$AssignedTo | Comma-separated usernames of assigned users |
User Registration: In addition to server-side variables, user registration templates use:
Variable Name | Description |
---|---|
$Ticket | Authentication token |
$DisplayName | User's display name |