Skip to main content
Skip table of contents

Template Engine

Overview

iWorkflow contains a template engine, similar to other workflow tools. Templates are also sometimes referred to as expressions or functions.

Templates allow you to insert dynamic data into your workflow actions, and even reference data that was output from previous actions.

Templatable Fields

It’s easy to identify a field that supports templates. Templatable fields have a blue gradient border around them and a different (monospace) font compared to a non-templatable field.

image-20240619-145806.png

An example of a standard (non-templatable) versus a templatable field.

Templates are Optional

Any field that can be templated does not have to be templated. The template language only recognizes text between {{}} or {%%} as template code. Anything not surrounded by those tags is treated as-is.

For example, on the HTTP action, the Method property is templatable, but you can just enter the word GET or POST directly - it does not have to be a template.

Template Language

iWorkflow uses a derivative of the Liquid template language. You can read a more in-depth introduction to the Liquid template language here.

We’ll cover the basics necessary for iWorkflow below.

Objects and Fields

Liquid evaluates and replaces any text inside {{ and }}. So, if you have a variable called greeting that was set to the value “Hi there”, you could write the following template and get this output:

Template

Output

{{ greeting }}, new Liquid user!

Hi there, new Liquid user!

Filters and Functions

Functions or methods in other languages are referred to as filters in Liquid. Filters can be used for a variety of things, such as converting a string to uppercase, formatting a date, parsing JSON, and lots more.

Filters are called by adding a pipe character (|) between the field and the filter. For example:

Template

Output

{{ "hello" | upcase }}

HELLO

Filters also support parameters - for example, the join filter joins an array together into a string and takes the delimiter as a parameter. So if you enter:

Template

Output

{{ ['a', 'b', 'c', 'd'] | join '-' }}

a-b-c-d

Data Types

Liquid supports the same data types that JSON does. You can use the type filter to get the data type name of an expression or variable.

iWorkflow also contains some special cases to work with JSON objects. In these cases, the data types will be JObject, JArray, etc.

Here are the supported data types for iWorkflow:

Template

Output

{{ 'a string' | type }}
or
{{ "a string" | type }}

string

{{ 47 | type }}

int

{{ 1.2 | type }}

double

{{ 2.3f | type }}

float

{{ true | type }}

boolean

{{ nil }}

null

{{ myJsonObject | type }}

jobject

{{ myJsonArray | type }}

jarray

{{ date.now | type }}

datetime

Whitespace

When writing templates, whitespace is generally preserved outside of the curly braces. By contrast, any whitespace contained between {{ and }} is generally ignored.

In the following table, the · symbol will represent an invisible space character.

Template

Output

·{{·message·}}··

·Hello··

{{····message·|·downcase··}}

hello

····{{message}}

····Hello

msg = ·{{·message·}}·

{"msg": "·Hello·"}

These examples show that anything outside of {{...}} is preserved, which can potentially add unwanted whitespace to your data.

Practical Examples

Referencing Data

Many actions will ask for an array or dataset as input. To provide the dataset, first find the { } Output Property from the previous action. The name you enter in the Output Property becomes a property on the input object.

For example, if you have a Fetch IQA Data action that is set to write an output property called memberDataset, then in an action below that, such as the Delta Hash action, you can provide the array as an input by providing this template expression:

ADA
{{ input.memberDataset }}

File Names

When using the FTP or SFTP actions, for example, you may need to create a random or date-based filename. You can achieve this with templates. For example:

ADA
// Randomized filename
my-test-file-{{ guid }}.csv

// Date-based filename
my-date-file-{{ date.now | format 'yyyy-MM-dd' }}.csv

Changing Data Types

If you have a dataset containing data in an incorrect format, for example numbers encased in strings ("100"), you can use the Select action in conjunction with the template engine to change the data type.

For example, if you had a dataset with a property called count that you wanted to convert from a string to a number, you could use the following select expression to parse the number as an integer:

ADA
{{ item.count | to_int }}

Your dataset would be altered like this:

Before

JSON
[
  { "count": "100" },
  { "count": "250" },
  { "count": "500" }
]

After

JSON
[
  { "count": 100 },
  { "count": 250 },
  { "count": 500 }
]
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.