Skip to content

Templates ​

Most fields in the nodes can be evaluated as templates. The default template engine is Jinja2 and expose all the buit-in's of the language.

To debug easily such fields, you can use the Template Playground reachable from the help section in the top bar.

It is extended with the following elements.

Filters ​

From Jinja2

FilterDescriptionSample
pp_dictturn an object into a pretty-printed JSON string representation{{ {'a': 1, 'b': 2} | pp_dict }}
dict_filterfilter a dictionary with a set of keys{{ {'a': 1, 'b': 2, 'c': 3} | dict_filter(['a', 'b']) }}
json_queryinspect a JSON object with a JMESPath query{{ {'a': 1, 'b': 2, 'c': 3} | json_query('a') }}
url_qsparse a URL query string into a dictionary{{ 'a=1&b=2&c=3' | url_qs }}
url_raw_queryparse a URL query string{{ 'a=1&b=2&c=3' | url_raw_query }}
jsonparse a JSON string into a dictionary{{ '{"a": 1, "b": 2, "c": 3}' | json }}
url_pathextract the path from a URL{{ 'http://apio.netaxis.cloud/api/v01/public/demo' | url_path }}
combinemerge dictionaries{{ {'a': 1, 'b': 2} | combine({'c': 3}) }}
rest2dictparse a REST call response into a dictionary (note: it automatically parse a body property as a JSON string into an object){{ rest2dict(rest) }}
regex_replaceuse a regular expression to replace a string{{ 'hello, world' | regex_replace('hello', 'goodbye') }}
regex_findalluse a regular expression to find all matches in a string{{ 'hello, world' | regex_findall('l') }}
regex_searchuse a regular expression to search a string{{ 'hello, world' | regex_search('l') }}
uniqueexclude duplicates from a list{{ [1, 2, 3, 1, 2, 3] | unique }}
intersectintersect two lists{{ [1, 2, 3] | intersect([2, 3, 4]) }}
differencedifference between two lists{{ [1, 2, 3] | difference([2, 3, 4]) }}
unionunion of two lists{{ [1, 2, 3] | union([2, 3, 4]) }}
minminimum value of a list{{ [1, 2, 3] | min }}
maxmaximum value of a list{{ [1, 2, 3] | max }}
b64encodebase64 encode a string{{ 'hello, world' | b64encode }}
b64decodebase64 decode a string{{ 'aGVsbG8sIHdvcmxk' | b64decode }}
phonenumber_validcheck if a phone number is valid{{ '+33612345678' | phonenumber_valid }}
phonenumber_e164convert a phone number to E164 format{{ '+33612345678' | phonenumber_e164 }}
phonenumber_ccextract the country code from a phone number{{ '+33612345678' | phonenumber_cc }}
phonenumber_ccaextract the country code from a phone number in alpha-2 format{{ '+33612345678' | phonenumber_cca }}
phonenumber_typeextract the type of a phone number{{ '+33612345678' | phonenumber_type }}
strftimeformat a date{{ '2021-01-01' | strftime('%Y-%m-%d') }}
to_datetimeconvert a string to a datetime object{{ '2021-01-01' | to_datetime }}
to_boolconvert a string to a boolean (evaluate to true: "yes", "on", "1", "true", 1){{ 'true' | to_bool }}
hmacgenerate hash for a string, using a key (optional); supported digests: sha1, sha224, sha256 (default), sha384, sha512, blake2b, blake2s{{ 'secret' | hmac }} {{ 'secret' | hmac('key') }} {{ 'secret' | hmac('key', 'sha512') }}
chunkedsplit a list into chunks{{ [1, 2, 3, 4, 5, 6] | chunked(2) | list }}

Tests ​

From Jinja2

Functions ​

FunctionDescriptionSample
nowcompute the current date and time{{ now() }}
tzapply a timezone to a date{{ now(tz('Europe/Paris')) }}
timedeltaapply a delta to a date{{ now() | timedelta(days=1) }}
utcnowcompute the current date and time in UTC{{ utcnow() }}
uuidgenerate a UUID{{ uuid() }}
randintgenerate a random integer{{ randint(1, 10) }}

Variables ​

Assignments from Jinja2

VariableDescription
requestthe current request object. Use {{ (request.body | rest2dict).<property> }} to access request body triggered by an HTTP custom endpoint
instancethe current instance object running a workflow with the following attributes: id, guid, callback_task_id, user_id, original_request_id, label
contexta key-value map attached to the current workflow instance
taskstasks ran until there with their status
sub_instances_responses"callback" responses produced by sub-instances
parent_instance_contextcontext of the parent instance (only filled in sub-instance)
settingsa dictionary containing the settings of the platform (sensitive content are removed for security reason)
enva dictionary containing the environment variables of the platform
proxy_namethe name of the proxy (only filled in processes started with proxy binding)
worker_enva dictionary containing the environment variables of the worker process (note: it allows to attach different values depending on the running location)
userthe user object of the current user (only filled when the instance has an owner defined)

Alternatives ​

While jinja2 is the default template engine, you can use other engines by specifying the engine attribute in the field (just under the template in the editor).

template-engines-alternatives

TIP

Jinja2 is a Python based template engine, so it is the most extensible and powerful engine available. But because it is Python based, it is not the fastest engine available. If you have a lot of templates to evaluate, or templates with big data or slow templates, you may want to consider using a faster and lighter engine like Pongo2.

Pongo2 ​

Documentation: https://github.com/flosch/pongo2