Versions Compared

Key

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

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.

...

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{{ format(123.456.789, 'string') }}123456789

Date formatting

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

...

{{format(MyDate, 'MMMM 09:00
TemplateOutputsCulture
{{ MyDate }}01/31/2014 16:04:12 +02:00
{{ format(MyDate,'MMM/yyyy/dd') }}Feb.2018.04
{{ format(MyDate,'MMM/yyyy/dd') }}Şub.2018.04tr-TR
/MM/yyyy') }}Nisan 2021tr-TR{{ format(MyDate) }}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

...

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

Text Masking

Template system also provides an mask function to filter displayed text on screen. This function can used to filter out personal data like name, credit card, identity number etc. More details can be found at mask function reference.

Code Block
{{ mask(DisplayName) }}					-> J*****D
{{ mask(CreditCard,4,4,'','-') }}		-> 1234-****-****-3456

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:

...