Skip to main content

Tailormade functions

To be a maximum safe on the generation, Watson provides multiples function that MUST be used in the template in order to access to some properties or check some data.

p(key)

p(key, placeholder = "-")

Prints the value of the key in example : "policy_owner.first_name", if the value is not accessible or defined in request it will print "-". This can be changed by the placeholder parameter. Note that the placeholder is not required, and will return "-" by default.

{{p("policy_owner.first_name", "N/A")}}

That will print "Bernard" if the data looks lile {policy_owner: first_name: "Bernard"}, otherwhise it will print "N/A"

a(key)

Required to iterate on every iteration of an array. Also guarantee to have an array even if the value behind the path doesn"t exists (template generation can fail if value is not an array)

{{FOR car IN a("cars.cars_multi")}}

In that case, if the data looks like {cars: {cars_multi: [{plate: "1"}, {plate: "2"}]}} it will return the array cars_multi from the data, if cars.cars_multi does not exists in the data, it will return an empty array []. That way Watson will not fail with an undefined object.

price(key, options, keyAsValue)

Prints the value and formats as a price (space separator & € symbol). "options" allows to customize the format. "keyAsValue" (boolean), allows to format directly a value passed as key

For the following, consider that the dataset it {premiums: {total: 1000.13}}

{{price("premiums.total")}}

Will print 1000,13 €

{{price("premiums.total", { symbol: "$" })}}

Will print 1000,13 $

{{price("premiums.total", { precision: 1 })}}

Will print 1000,1 €

{{price("premiums.total", { decimal: "." })}}

Will print 1000.13 €

{{price("premiums.total", { pattern: "! #" })}}

Will print € 1000,13, usefull in dutch for example where € is placed in front of the amount.

Note that all options are combinable.

{{price(150000, null, true)}}

Will print 150 000 €, the third parameter say that the first parameter is a value to display as a price and not a path to a value in the dataset.

checkBool(key)

Utility to use in template conditions, in order to check if value is true or false

{{checkBool("premiums.liability.selected")}}

Make sure to return a boolean, and not possibly undefined

moment(key)

Prints the value and formats a date as you want. It"s a implementation of the momentjs library. All the methods, format, in the documentation are available

{{moment("policy_owner.date_of_birth", "DD/MM/YYYY")}}

With a dataset like {policy_owner: {date_of_birth: 2000-01-01}} will print 01/01/2000

t(key)

When Watson generates a document, it also receive a locale and an in the dataset, an object translations can be found e.g.

{
// all other data
translations: {
en: {
hello: "Hello"
},
fr: {
hello: "Bonjour"
}
}
}

It will automatically looks on the available translations. The locale used for the template is the one defined when uploading the document template in the product factory

{{t("policy_owner.date_of_birth")}} Will looks in translation for "translations.fr.policy_owner.date_of_birth"

{{t(policy_owner_kind)}} With a dataset {policy_owner_kind: "company"}, will looks in translation for the VALUE of policy_owner_kind => "translations.fr.company"

{{t(policy_owner_kind.selected_list_item.__label)}} If value of provided key is an object with {fr: "",nl: ""} it will automatically get the locale

i(key, widthInCm, angle)

Method used to print image in the document, the size of the image can be specified (in cm) and if resized the image will keep its aspect ratio. Also we can set the rotation angle of the picture, useful if printing a large image on a full page.

{{IMAGE i("kitchen.uploads.0.blob.file_url")}}

Will looks in data for "kitchen.uploads.0.blob.file_url" and prints the image

{{IMAGE i("kitchen.uploads.0.blob.file_url", 5)}}

Will looks in data for "kitchen.uploads.0.blob.file_url" and prints the image at 5cm of width

{{IMAGE i("kitchen.uploads.0.blob.file_url", 20, 90)}} Will looks in data for "kitchen.uploads.0.blob.file_url" and prints the image at 20cm of width and rotated at +90°

Signature

For some document, when it"s generated, it can be sent to another service that can add a digital signature to the document, this tag allows the user to specify the place where that signature should be in the document.

{{signature}}