Word Template Reference v1
Loops
FOR
and END-FOR
Loop over a group of elements (resulting from the evaluation of a JavaScript expression):
{{FOR person IN project.people}}{{$person.name}} (since {{$person.since}}){{END-FOR person}}
Note that inside the loop, the variable relative to the current element being processed must be prefixed with $
.
It is possible to get the current element index of the inner-most loop with the variable $idx
, starting from 0
. Also nested loops are supported. For example:
{{FOR company IN companies}}Company ({{$idx}}): {{$company.name}}Executives:{{FOR executive IN $company.executives}}- {{$idx}} {{$executive}}{{END-FOR executive}}{{END-FOR company}}
Since JavaScript expressions are supported, you can for example filter the loop domain:
{{FOR person IN project.people.filter(person => person.since > 2013)}}...
Tables
Loops are also supported within tables.
Important:
FOR and END-FOR command on empty rows.
The loop variable needs to be referenced with a $
Name | Last Name |
{{FOR person IN persons}} |
|
{{$person.name}} | {{$person.surname}} |
{{END-FOR person}} |
|
Conditions
IF
and END-IF
Include contents conditionally (depending on the evaluation of a JavaScript expression):
{{IF person.name === 'Guillermo'}}{{person.fullName}}{{END-IF}}
Similarly to the FOR
command, it also works over table rows. You can also nest IF
commands and mix & match IF
and FOR
commands.
Since under the hood IdealDoc works with javascript objects all properties and methods of the related javascript object can be used. For example is a collection of records a javascript array and therefore expressions like this are possible:
{{IF persons.length > 0}}Do Something with the persons array{{END-IF}}
Images
Images can be inserted through the {{IMAGE ...}}
directive. The image can either be loaded from a public URL or passed as a base64 encoded string. The commands look like this:
From URL: {{IMAGE $url("https://myimagurl.com",<width>,<height>,"<extension>")}}
From Base64: {{IMAGE $base64("MYIMAGEBASE64DATA",<width>,<height>,"<extension>")}}
The width and height are optional and in measured in CM. If the width and height are omitted the original image size will be used. Passing a size of zero has the same meaning as omitting the parameter. If only the width or the height is provided the other dimension gets calculated maintaining the original aspect ratio. The extension, e.g. “png” is also optional. For example:
{{IMAGE $url(person.photoUrl,0,3)}}
The image from the url stored in the person variable will be displayed with a height of 3 cm and a width calculated maintaining the aspect ratio. The extension will be detected automatically.
Links
TheLINK
directive creates a hyperlink with the data resulting from evaluating a JavaScript snippet:
{{LINK ({ url: project.url, label: project.name })}}
If the label
is not specified, the URL is used as a label.
Date / Date Time Fields
Formatting date or date and time strings is supported through a built in $date() function.
{{$date(<date/time string>, [format pattern])}}
The shortcut function $today can be used to display the current date or date time.
{{$today([format pattern])}}
The provided date/time string needs to be in ISO 8601 format. For example:
‘2018-04-04T16:00:00.000Z'
'2018-04-13 19:18:17.040+02:00'
'2018-04-13 19:18'
'2018-04-13’
The format pattern is optional and needs to follow the date formatting specification described here. If no format pattern is provided the format pattern from the provided json configuration or the default pattern will be used. for example:
{{$date(createdDate)}}
{{$dateTime(createdDateTime)}}
{{$dateTime(createdDateTime, "D.M.YYYY hh:mm:ss")}}
{{$today("D.M.YYYY hh:mm:ss")}}
Number Fields
Formatting numbers is supported through the built in $number() function.
Counter
To count rows in a table, this function is available:
{{$idx}}
It starts at 0. To start at 1 : {{$idx+1}} .
Rich Text
Rich text (i.e. formatted text) can be inserted into the docx document using HTML snippets. The directive to use is HTML
. It takes the HTML resulting from evaluating a JavaScript snippet and converts it to Word contents.
Important: This uses altchunk, which is only supported in Microsoft Word, and not in e.g. LibreOffice or Google Docs.
Since the html might contain single or double quotes, the direct html content needs to be enclosed in special single quotes!
{{HTML `<meta charset="UTF-8"><body><h1>${$film.title}</h1><h3>${$film.releaseDate.slice(0, 4)}</h3><p><strong style="color: red;">This paragraph should be red and strong</strong></p></body>`}}
If the provided html snippet is not enclosed within a <body> tag (as for example the case for html stored in Salesforce rich text fields) the built in $html function should be used to create the proper html. For example:
{{HTML $html(Description)}}
With the $html function the font family and the font size can be passed as optional parameter. E.g.
{{HTML $html(Description, "arial", 14)}}
Swiss QR Bill (Invoice)
IdealDoc supports the creation of the Swiss QR Bill natively. In order to generate a Swiss QR Bill the built in function:
{{$swissQRBill
()}}
Can be used. In order for the Swiss QR Bill to display correctly the following data needs to be provided in the defined structure:
$swissQRBillData.options.language": "DE",
"$swissQRBillData.options.svgWidth": 18.49,
"$swissQRBillData.options.svgHeight": 9.34,
"$swissQRBillData.creditor.name": "IdealTeam.Group AG",
"$swissQRBillData.creditor.address": "Bächlerstrasse 30",
"$swissQRBillData.creditor.zip": "8802",
"$swissQRBillData.creditor.city": "Kilchberg ZH",
"$swissQRBillData.creditor.account": "CH370029329311538901Q",
"$swissQRBillData.creditor.country": "CH",
"$swissQRBillData.debtor.name": "Customer Name",
"$swissQRBillData.debtor.address": "Customer Street",
"$swissQRBillData.debtor.zip": "Customer ZIP",
"$swissQRBillData.debtor.city": "Customer City",
"$swissQRBillData.debtor.country": "Customer Country Code",
"$swissQRBillData.currency": "CurrencyIsoCode",
"$swissQRBillData.amount": 1234.50,
"$swissQRBillData.reference": "REF NR",
Helper Functions
$empty()
: Check for empty fields (i.e. null or "")
$exists()
: Check whether a field exists at all