Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Data templates transforms Data templates transform the data model into text or HTML content. Templates are used in many areas in emakin like form controls or mail templates etc.

Templates basically consist on of xpath queries within {{ and }} qualifiers.

Assume you have a field named as "username" in the data model. Basic temple template example is:

Code Block
languagejs
Hello {{ username }}!

...

Because all xml values are string by default, no formatting is performed while generating the output. If you need to perform formatting for number or date values, you have to convert the data type or use a format function.

Culture Support

Data templates are culture sensitive and all formatting rules are derived from culture being used. Culture information is automatically derived from user preferences or you can explicitly specify it. If no culture is specified, invariant culture is used.

...

All text or string types are exactly transformed without any format formatting being performed.

Number formatting

Functions like "Sum" or "Count" already return number values, therefore there is no need for number conversions, but incase in case it is necessary, number() function should be used. Ex: number(MyNumberField) 

All number values are by default formatted with decimal rules.

Examples:

TemplateOutputsCulture
{{ 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,00tr-TR
{{ format( number(123456789), 'n0') }}123,456,789
 

{{ format(number(123456789), 'c') }}123.456.789,00 ₺tr-TR

Date formatting

Template system does automatically detects the xml date types in formatted with "YYYY-MM-DD-THH:MM:SSTZ". Emakin always use uses this format in data model for date values.

...

Examples:

Assume data model has an a MyDate field with 2014-01-31T09:00:00+02:00 value.

TemplateOutputsCulture
{{ MyDate }}01/31/2014 16:04:12 +02:00
 

{{ format(MyDate,'dd/MM/yyyy') }}31/01/2014
 

{{ format(MyDate) }}31.1.2014 09:00tr-TR
{{ format(MyDate,'d') }}31/01/2014
{{ format(MyDate,'D') }}Monday, June 15, 2009en-US
{{ format(MyDate,'o') }}
2014-01-31T09:00:00+02:00
 

Scripting example

Code Block
var myNode = $Xml.Parse("<Customer><Name>John</Name><BirthDate>2014-01-31T09:00:00+02:00</BirthDate></Customer");
var result = myNode.Format('<p>Birth date : {{Customer/BirthDate}}</p>');

// result : <p>Birth date : 01/31/2014 09:00:00 +02:00</p>

...

A way to remove time from date node:

Code Block
$Xml.SetValue('Test/testdate', new DateTimeOffset());  // testdate will be saved to an XML as "2015-11-12T15:27:16.2568549+02:00"
$Xml.SetValue('Test/testdate2', $Xml.Format("{{ format(Test/testdate,'yyyy-MM-dd') }}"));  // testdate2 will be saved to an XML as "2015-12-11"

// result : 2015-12-11

Format Function Options

Data TypeFormat OptionDescriptionSample DataOutput
String
Print string as automatically detection<script>alert('hello')</script><div>hello</div><div>hello</div>
String
Print string as automatically detection12.34512.3
String
Print string as automatically detection1212
String
Print string as automatically detection2022-05-07T00:00:00+03:0007.05.2022 00:00
String
Print string as automatically detectionTrue / true✓ (U+2713)
String
Print string as automatically detectionFalse / false✕ (U+2715)
StringhtmlPrint string as encoded html text<script>alert('hello')</script><div>hello</div>"<script>alert('hello')</script><div>hello</div>"
StringsafePrint value as safe html with discarding dangerous tags<script>alert('hello')</script><div>hello</div><div>hello</div>
StringstringPrint string without any encoding applied<script>alert('hello')</script><div>hello</div><script>alert('hello')</script><div>hello</div>
Numbern0Print number as integer without any decimal12.34512
Numbern1Print number as decimal with 1 number after dot12.34512.3
Boolean
Print value as unicode check markTrue / true✓ (U+2713)
Boolean
Print value as unicode check markFalse / false✕ (U+2715)
DateTime
Print date value in user's locale preference2022-05-07T00:00:00+03:0007.05.2022 00:00
DateTimeoPrint date in ISO format2022-05-07T00:00:00+03:002022-05-07T00:00:00+03:00
DateTimemPrint date in dynamic formatted format2022-05-07T00:00:00+03:002 days ago
DateTimedd/MM/yyyyPrint date in specified date format2022-05-07T00:00:00+03:0007/05/2022

Conditional Formatting

If conditional rendering is needed, the format below can be used;:

Code Block
languagexml
if XPathConditon then Template
if XPathConditon then Template else Template

...

If you need to apply template for multiple nodes in a data model, you can use repeating template expression like following syntax:

Code Block
ItemXPath => Template

This format applies the same template for every matched element by ItemXPath.

...

While generating HTML content some tags ( like table tag ) may become corrupted if {{ x => y}} template is used. As an alternative method, format function supports the x-repeat attribute to perform the repeating content. 

Code Block
languagexml
{{ SAMPLE REPORT
   <table>
     <tr x-repeat="Rows/Row">
       <td>{{Date}}</td><td>{{Description}}</td>
     </tr>
   </table> }}

This attribute can be used with any element. For example, it can also be used with "li" tag also.

Code Block
{{ <ul>
     <li x-repeat="Rows/Row">
       <span>{{Date}}</span>
     </li>
  </ul> }}

...

If recursive repeating templates are being needed, format below can be used;:

Code Block
ItemXPath =>> Template

For each item at specified in ItemXPath, sub template is generated, and also the same template is repeated again for the Template content recursively.

...

Code Block
languagexml
<h1>SAMPLE REPORT</h1>
<h2>My Section</h2>
<p>Section content</p>
<h2>Sub Section</h2>
<p>Child section content</p>

Template Variables

All of the custom defined process variables can be use used in templates. Additionally, some of the system properties are automatically imported to the template engine. Because of the environment limits, client and server side variables uses use different variable contexts.

Client Template Variables

In form scripts like form script, for the validation rules that running in on the client side environment, following variables are defined;:

Variable NameDescription
$staticUrlStatic resources base address. (ex: https://static.emakin.com/ )
$applicationUrlApplication base address. (ex: https://mydomain.emakin.com/app/ )
$ProcessUnique identifier of the current process. (ex: 71E8B187-C049-4ba1-AE5E-6B0BAD6B7F42 )
$FolderNameName of the current folder
that
in which the process is saved. (ex: Customer Relations )
$CustomVariableDefined custom value.

Server Template Variables

In process scripts like pre work, post work and other scripts that running in on the server side environment, following variables are defined;:

Variable NameDescription
$ApplicationNameName of an application. (ex: emakin.com )
$ApplicationUrlBase url of an application (ex: emakin.com )
$DomainName
$Domain.NameName of a domain (ex: mydomain)
$DomainUrl
$Domain.UrlUrl of a domain (ex: https://mydomain.emakin.com )
$DomainLogo
$Domain.LogoUrlLogo image url of a domain (ex: https://mydomain.emakin.com/logo.png )
$CustomVariableDefined custom value.

Activity Notification Template

Activity notifications, like assigning a work item to a user or reminder notifications uses , use the same template context. Addition Additionally to the server variables, the following variables can also can be used;:

Variable NameDescription
$IdId number of a work item
$WorkItemInstance of WorkItem. You can use . (dot) qualifier to access object properties like "$WorkItem.Instance.Number"
$RecipientsComma qualified recipient names. (ex: Ertan Tike, Emel Sayın)
$UrlUrl of a work item. (ex: https://mydomain.emakin.com/app/?/workitem=1234 )
$AssignedToComma qualified
user names of that
username of user to whom the work item is assigned. (ex: Ertan Tike)

User Registration Template

Addition Additionally to the server variables user variables, user registration invitation defines the following variables;:

Variable NameDescription
$TicketDefines the system generated authentication token to
embed
be embedded in a mail content.
$DisplayNameDefines the display name of a user.

 

 

...