Skip to main content

Templating syntax

Here you'll undestand how to write template for further uploading it to your stack and then call the API to get pdf return with filled data.

warning

Currently there is no validation for template available. So read this documentation careful before creating templates


Supported commands

Currently supported commands are defined below.

Setting value

Inserts the result of a given snippet.

Data to send:

{ 
project: {
name: "Healthcare Molecules",
url: "https://molecules.health",
people: [{
name: "Jack Olson", since: 2005
}, {
name: "Alisa Talor", since: 2007
}, {
name: "Amanda Write", since: 20011
}]
details: {
year: 1992
}
},
companies: [{
name: "Healthcare development",
people: [{
firstName: "Brandon",
projects: [{
name: "Cancer laser therapy"
}, {
name: "Cough stimulator"
}, {
name: "Medicine ecology"
}]
}],
executives: ["Anna May", "Clare Atmos"]
}]
}

Write in docx file:

{{project.name}} ({{project.details.year}})
or...
{{`${project.name} (${project.details.year})`}}

will result in

Healthcare Molecules (1992)

Includes 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.

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. For example:

{{FOR company IN companies}}
Company ({{$idx}}): {{$company.name}}
Executives:
{{FOR executive IN $company.executives}}
- {{$idx}} {{$executive}}
{{END-FOR executive}}
{{END-FOR company}}

FOR loops also work over table rows:

NameSince
{{FOR person IN project.people}}
{{$person.name}}{{$person.since}}
{{END-FOR person}}

Finally, you can nest loops (this example assumes a different data set):

{{FOR company IN companies}}
{{$company.name}}
{{FOR person IN $company.people}}
* {{$person.firstName}}
{{FOR project IN $person.projects}}
- {{$project.name}}
{{END-FOR project}}
{{END-FOR person}}
{{END-FOR company}}

IMAGE

Includes an image with the data resulting from evaluating a JavaScript snippet:

+++IMAGE readImage(width, height, url, extension)+++

where

  • width: desired width of the image on the page in cm. Note that the aspect ratio should match that of the input image to avoid stretching.
  • height desired height of the image on the page in cm.
  • data: either an ArrayBuffer or a base64 string with the image data
  • extension: one of '.png', '.gif', '.jpg', '.jpeg'.
note

Currently '.png' image is tested but there is a posibility to try '.jpg', '.jpeg', '.gif'