Handlebars are deprecated and superseded by Pebble. These functions will be removed soon and are disabled by default.

boolean

eq: Equality

Test if two elements are equals.

Render yes or no:

handlebars
  {{ #eq a b }}
    yes
  {{ else }}
    no
  {{ /eq }}

Render true or false:

handlebars
  {{ eq a b }}

Render yes or no:

handlebars
  {{ eq a b yes='yes' no='no' }}

neq: Not equality

Test if two elements are NOT equals.

Render yes or no:

handlebars
  {{ #neq a b }}
    yes
  {{ else }}
    no
  {{ /neq }}

Render true or false:

handlebars
  {{ neq a b }}

Render yes or no:

handlebars
  {{ neq a b yes='yes' no='no' }}

gt: Greater operator

Greater operator (arguments must be Comparable elements).

Render yes or no:

handlebars
  {{ #gt a b }}
    yes
  {{ else }}
    no
  {{ /gt }}

Render true or false:

handlebars
  {{ gt a b }}

Render yes or no:

handlebars
  {{ gte a b yes='yes' no='no' }}

gte: Greater or equal operator

Greater or equal operator (arguments must be Comparable elements).

Render yes or no:

handlebars
  {{ #gte a b }}
    yes
  {{ else }}
    no
  {{ /gte }}

Render true or false:

handlebars
  {{ gte a b }}

Render yes or no:

handlebars
  {{ gte a b yes='yes' no='no' }}

lt: Less operator

Less than operator (arguments must be Comparable elements).

Render yes or no:

handlebars
  {{ #lt a b }}
    yes
  {{ else }}
    no
  {{ /lt }}

Render true or false:

handlebars
  {{ lt a b }}

Render yes or no:

handlebars
  {{ lt a b yes='yes' no='no' }}

lte: Less or equal operator

Less than operator (arguments must be Comparable elements.

Render yes or no:

handlebars
  {{ #lte a b }}
    yes
  {{ else }}
    no
  {{ /lte }}

Render true or false:

handlebars
  {{ lte a b }}

Render yes or no:

handlebars
  {{ lte a b yes='yes' no='no' }}

and: And operator

And operator. This is a boolean operation.

Truthiness of arguments is determined by isEmpty, so this helper can be used with non-boolean values.

Multiple arguments are supported too:

handlebars
  {{ #and a b c d }}
    yes
  {{ else }}
    no
  {{ /and }}

Render yes or no:

handlebars
  {{ #and a b }}
    yes
  {{ else}}
    no
  {{ /and }}

Render true or false:

handlebars
  {{ and a b }}

Render yes or no:

handlebars
  {{ and a b yes='yes' no='no' }}

or: Or operator

Or operator. This is a boolean operation

Truthiness of arguments is determined by isEmpty, so this helper can be used with non-boolean values.

Multiple arguments are supported too:

handlebars
  {{ #or a b c d }}
    yes
  {{ else }}
    no
  {{ /or }}

Render yes or no:

handlebars
  {{ #or a b }}
    yes
  {{ else }}
    no
  {{ /or }}

Render true or false:

handlebars
  {{ or a b }}

Render yes or no:

handlebars
  {{ or a b yes='yes' no='no' }}

not: Not operator

Truthiness of arguments is determined by isEmpty, so this helper can be used with non-boolean values.

Render yes or no:

handlebars
  {{ #not a }}
    yes
  {{ else }}
    no
  {{ /not }}

Render true or false:

handlebars
  {{ not a }}

Render y or n:

handlebars
  {{ not a yes='yes' no='no' }}

cmp: Compare operator

Compare to object as Comparables.

Renders 1 if a > b, 0 if a == b -1 if a < b

handlebars
  {{ cmp a b }}

isNull: Compare operator

Test if one element is null.

handlebars
  {{ isNull a }}

isNotNull: Compare operator

Test if one element is not null.

handlebars
  {{ isNotNull a }}

date

dateFormat: Date format

handlebars
{{ dateFormat date ['format'] [format='format'][tz=timeZone | timeZoneId] }}

## Arguments:

  • format: Format parameters is one of:
    • full: Sunday, September 8, 2013 at 4:19:12 PM Central European Summer Time
    • long: September 8, 2013 at 4:19:12 PM CEST
    • medium: Sep 8, 2013, 4:19:12 PM
    • short: 9/8/13, 4:19 PM
    • iso: 2013-09-08T16:19:12.000000+02:00
    • iso_sec: 2013-09-08T16:19:12+02:00
    • sql: 2013-09-08 16:19:12.000000
    • sql_seq: 2013-09-08 16:19:12
    • iso_date_time: 2013-09-08T16:19:12+02:00Europe/Paris
    • iso_date: 2013-09-08+02:00
    • iso_time: 16:19:12+02:00
    • iso_local_date: 2013-09-08
    • iso_instant: 2013-09-08T14:19:12Z
    • iso_local_date_time: 2013-09-08T16:19:12
    • iso_local_time: 16:19:12
    • iso_offset_time: 16:19:12+02:00
    • iso_ordinal_date: 2013-251+02:00
    • iso_week_date: 2013-W36-7+02:00
    • iso_zoned_date_time: 2013-09-08T16:19:12+02:00Europe/Paris
    • rfc_1123_date_time: Sun, 8 Sep 2013 16:19:12 +0200
    • pattern: a date pattern.
    • Otherwise, the default formatter iso will be used. The format option can be specified as a parameter or hash (a.k.a named parameter).
    • You can pass the any format from SimpleDateFormat
  • timezeome: with the format Europe/Paris

now: Current date

handlebars
   {{ now ['format'] [tz=timeZone|timeZoneId] }}

## Arguments:

  • format: Same format as dateFormat
  • timezone: with the format Europe/Paris

timestamp: Current second timestamp

handlebars
   {{ timestamp }}

nanotimestamp: Current nano timestamp

handlebars
   {{ nanotimestamp }}

microtimestamp: Current micro timestamp

handlebars
   {{ microtimestamp }}

dateAdd: Add some units to date

handlebars
   {{ dateAdd yourDate quantity "unit" [format="format"] [tz=timeZone|timeZoneId] }}
   {{ dateAdd yourDate -1 "DAYS" }}
  • quantity: an integer value positive or negative
  • format: Format parameters is one of:
    • NANOS
    • MICROS
    • MILLIS
    • SECONDS
    • MINUTES
    • HOURS
    • HALF_DAYS
    • DAYS
    • WEEKS
    • MONTHS
    • YEARS
    • DECADES
    • CENTURIES
    • MILLENNIA
    • ERAS

index

Variables are specific fields for tasks. They use the power of handlebars with Kestra's special context system, allowing powerful task composition.

Variables can use variable information registered/existing in the execution context. The context is data injected in Variables and from different sources:

Functions

Sometimes, you need to change the format of variables. To do this, you can use some of the following functions:

---

iterations

For each

You can iterate over a list using the built-in each helper. Inside the block, you can use this to reference the element being iterated over. contextualListVariable is an iterable item on which the mydata property is displayed for all entries.

The @index is a special variable available in the each loop context which value is the current index of the element being iterated. There are agic* variables like @index in a each context. The following ones are also available: @key @index @first @last @odd @even

See handlebars documentation for more about this topic.

handlebars
{{ #each contextualListVariable }}
    {{ this.mydata }} {{ @index   }}
{{ /each }}

will produce

one 0
two 1
three 2
django! 3

for the following data sample when

javascript
contextualListVariable = [
  {"mydata": "one"},
  {"mydata": "two"},
  {"mydata": "three"},
  {"mydata": "django!"},
]

If the contextual 'this' is not convenient to use the data as you wish, it is possible to alias it as shown below:

handlebars
{{ #each iterableVariable as | myItem | }}
    {{myItem.mydata}}
{{ /each }}

json

json Convert an object to json

Convert an object to is JSON representation

handlebars
{{ json output['task-id'] }}

Example, if the current context is:

json
{
  "outputs": {
    "task1": {
      "value": 1,
      "text": "awesome1"
    },
    "task2": {
      "value": 2,
      "text": "awesome2"
    }
  }
}

the output of {{ json outputs.task2}} will be {"value":2,"text":"awesome2"}.

jq Transform vars with JQ

Apply the JQ expression to a variables.

handlebars
{{ jq vars jqExpr [first=false] }}

first mean to always fetch the first element, by default jq return an array of results

Example, if the current context is:

json
{
  "outputs": {
    "task1": {
      "value": 1,
      "text": "awesome1"
    },
    "task2": {
      "value": 2,
      "text": "awesome2"
    }
  }
}
handlebars
{{ jq outputs .task1.value true }}

the output will be 1.


number

numberFormat: Format a number

handlebars
   {{ numberFormat number ["format"] [locale=default] }}

Arguments:

  • format: Format parameters is one of:
    • "integer": the integer number format
    • "percent": the percent number format
    • "currency": the decimal number format
    • "pattern": a decimal pattern.
    • Otherwise, the default formatter will be used.

More options:

  • groupingUsed: Set whether or not grouping will be used in this format.
  • maximumFractionDigits: Sets the maximum number of digits allowed in the fraction portion of a number.
  • maximumIntegerDigits: Sets the maximum number of digits allowed in the integer portion of a number
  • minimumFractionDigits: Sets the minimum number of digits allowed in the fraction portion of a number
  • minimumIntegerDigits: Sets the minimum number of digits allowed in the integer portion of a number.
  • parseIntegerOnly: Sets whether or not numbers should be parsed as integers only.
  • roundingMode: Sets the {@link java.math.RoundingMode} used in this NumberFormat.

string

capitalizeFirst: Capitalizes the first character of the value.

If the value is "kestra is cool !", the output will be "Kestra is cool !".

handlebars
{{ capitalizeFirst value }}

center: Centers the value in a field of a given width.

If the value is "Handlebars.java", the output will be " Handlebars.java ".

handlebars
{{ center value size=19 [pad="char"] }}

## Arguments:

  • size
  • pad

cut: Removes all values of arg from the given string.

If the value is "String with spaces", the output will be "Stringwithspaces".

handlebars
{{ cut value [" "] }}

defaultIfEmpty: Default if empty

If the value evaluates to False, it will use the given default. Otherwise, it uses the value. If value is "" (an empty string), the output will be nothing.

handlebars
{{ defaultIfEmpty value ["nothing"] }}

join: Join string

Joins an array, iterator or an iterable with a string.

handlebars
{{ join value join [prefix=""] [suffix=""] }}

## Arguments:

  • join
  • prefix
  • suffix

If value is the list 'a', 'b', 'c', the output will be the string "a // b // c".

handlebars
{{ join value " // " [prefix=""] [suffix=""] }}

Join the "a", "b", "c", the output will be the string "a // b // c".

handlebars
{{ join "a" "b" "c" " // " [prefix=""] [suffix=""] }}

ljust: Left-aligns the value in a field of a given width.

If the value is Handlebars.java, the output will be "Handlebars.java ".

handlebars
{{ ljust value 20 [pad=" "] }}

## Arguments:

  • field size

rjust: Right-aligns the value in a field of a given width.

If the value is Handlebars.java, the output will be " Handlebars.java".

handlebars
{{ rjust value 20 [pad=" "] }}

## Arguments:

  • field size
  • pad

substring Substring

Returns a new CharSequence that is a subsequence of this sequence. The subsequence starts with the char value at the specified index and ends with the char value at nd - 1*

handlebars
{{substring value start end }}

## Arguments:

  • start offset
  • end offset

For example:

If the value is Handlebars.java, the output will be "java".

handlebars
{{ substring value 11 }}

If the value is Handlebars.java, the output will be "Handlebars".

handlebars
{{ substring value 0 10 }}

lower: Converts a string into all lowercase.

If the value is 'Still MAD At Yoko', the output will be 'still mad at yoko'.

handlebars
{{ lower value}}

upper Converts a string into all uppercase.

If the value is 'Hello', the output will be 'HELLO'.

handlebars
{{ upper value }}

slugify Converts to lowercase

This removes non-word characters (alphanumerics and underscores) and converts spaces to hyphens. It also strips leading and trailing whitespace. If the value is "Joel is a slug", the output will be "joel-is-a-slug".

handlebars
{{ slugify value }}

stringFormat: Formats the variable

According to the argument, a string formatting specifier. If the value is "Hello %s" "handlebars.java", the output will be "Hello handlebars.java".

handlebars
{{stringFormat string param0 param1 ... paramN}}

## Arguments:

  • format
  • paramN

stripTags: Strips all XHTML tags.

handlebars
{{ stripTags value }}

capitalize: Capitalizes all the whitespace separated words in a String.

If the value is "my first post", the output will be "My First Post".

handlebars
{{ capitalize value [fully=false] }}

Arguments:

  • fully

abbreviate: Truncates a string

The string will be truncated if it is longer than the specified number of characters. Truncated strings will end with a translatable ellipsis sequence ("..."). If value is "Handlebars rocks", the output will be "Handlebars...".

handlebars
{{ abbreviate value 13 }}

## Arguments:

  • Number of characters to truncate to

wordWrap: Wraps words

This wraps the sentence at a specified line length. If value is Joel is a slug, the output would be: Joel\nis a\nslug

handlebars
{{ wordWrap value 5 }}

## Arguments:

  • the number of characters at which to wrap the text

replace Replaces

Each substring of this string that matches the literal target sequence with the specified literal replacement sequence. If value is "Handlebars ...", the output will be "Handlebars rocks".

handlebars
{{ replace value "..." "rocks" }}

yesno: Boolean to yes / no

For true, false and (optionally) null, to the strings "yes", "no", "maybe".

## Arguments:

  • yes
  • no
  • maybe
handlebars
{{ yesno value [yes="yes"] [no="no"] maybe=["maybe"] }}

use

Here you will find some examples to illustrate the available variables, and how to get the value you need.

Here is a typical payload for variables:

yaml
globals:
  my-global-string: string
  my-global-int: 1
  my-global-bool: true

task:
  id: float
  type: io.kestra.plugin.core.debug.Return

taskrun:
  id: 5vPQJxRGCgJJ4mubuIJOUf
  startDate: 2020-12-18T12:46:36.018869Z
  attemptsCount: 0
  value: value2

parent:
  taskrun:
    value: valueA
  outputs:
    int: 1

parents:
  - taskrun:
      value: valueA
    outputs:
      int: 1
  - taskrun:
      value: valueB
    outputs:
      int: 2

flow:
  id: inputs
  namespace: io.kestra.tests

execution:
  id: 42mXSJ1MRCdEhpbGNPqeES
  startDate: 2020-12-18T12:45:28.489187Z

outputs:
  my-task-id-1: # standard task outputs
    value: output-string
  my-task-id-2: # standard task outputs
    value: 42
  my-each-task-id: # dynamic task (each)
    value1: # outputs for value1
      value: here is value1
    value2: # outputs for value2
      value: here is value2

inputs:
  file: kestra:///org/kestra/tests/inputs/executions/42mXSJ1MRCdEhpbGNPqeES/inputs/file/application.yml
  string: myString
  instant: 2019-10-06T18:27:49Z

Common variables As you can see, there are a lot of common variables that can be used in your flow, some of the most common examples are: {{ execution.id }}, {{ execution.startDate }} that allows you to change a file name or SQL query, for example.

Input variables Input variables are simple to access with {{ execution.NAME }}, where NAME is the name of the declared in your flow. The data will be dependent on the type of the inputs. One special case for input variables is the FILE type, where the file is prepended by kestra://. This means the file is inside the internal Kestra storage. Most tasks will take this kind of URI as a property and will provide the same property output. This type of input variable allows the full file generated by one task to be used in another task.

Outputs variables One of Kestra's most important abilities is to use all outputs from previous tasks in the next one.

Without dynamic tasks (Each) This is the simplest and most common way to use outputs in the next task. In order to fetch a variable, just use {{ outputs.ID.NAME }} where:

  • ID is the task id
  • NAME is the name of the output. Each task type can have any outputs that are documented on the part outputs of their docs. For example, Bash task can have {{ outputs.ID.exitCode }}, {{ outputs.ID.outputFiles }}, {{ outputs.ID.stdErrLineCount }}, etc...

With dynamic tasks (Each) This option is more complicated since Kestra will change the way the outputs are generated, since there can be multiple tasks with the same id, you will need to use {{ outputs.ID.VALUE.NAME }}.

Most of the time, using Dynamic Tasks, you will need to fetch the current value of the iteration. This is done easily with {{ taskrun.value }}.

But what if a more complex flow is built, for example, with each containing 1 task (t1) to download a file (based on each value), and a second one (t2) that needs the output of t1. Such a flow would look something like this:

yaml
id: each-sequential-nested
namespace: io.kestra.tests

tasks:
  - id: each
    type: io.kestra.plugin.core.flow.EachSequential
    value: '["s1", "s2", "s3"]'
    tasks:
      - id: t1
        type: io.kestra.plugin.core.debug.Return
        format: "{{ task.id }} > {{ taskrun.value }}"
      - id: t2
        type: io.kestra.plugin.core.debug.Return
        format: "{{ task.id }} > {{ (get outputs.t1 taskrun.value).value }} > {{ taskrun.startDate }}"
  - id: end
    type: io.kestra.plugin.core.debug.Return
    format: "{{ task.id }}"

In this case, you would need to use {{ (get outputs.t1 taskrun.value).value }}, which means give me from outputs.t1 the index results from taskrun.value.

With Flowable Task nested. If you have many Flowable Tasks, it can be complex to use the get function, and moreover, the taskrun.value is only available during the direct task from each. If you have any Flowable Tasks after, the taskrun.value of the first iteration will be lost (or overwritten). To deal with this, we have included the parent & parents vars.

This is illustrated in the flow below:

yaml
id: each-switch
namespace: io.kestra.tests

tasks:
  - id: t1
    type: io.kestra.plugin.core.debug.Return
    format: "{{ task.id }} > {{ taskrun.startDate }}"
  - id: 2_each
    type: io.kestra.plugin.core.flow.EachSequential
    value: '["a", "b"]'
    tasks:
      # Switch
      - id: 2-1_switch
        type: io.kestra.plugin.core.flow.Switch
        value: "{{ taskrun.value }}"
        cases:
          a:
            - id: 2-1_switch-letter-a
              type: io.kestra.plugin.core.debug.Return
              format: "{{ task.id }}"
          b:
            - id: 2-1_switch-letter-b
              type: io.kestra.plugin.core.debug.Return
              format: "{{ task.id }}"

            - id: 2-1_each
              type: io.kestra.plugin.core.flow.EachSequential
              value: '["1", "2"]'
              tasks:
              - id: 2-1-1_switch
                type: io.kestra.plugin.core.flow.Switch
                value: "{{ taskrun.value }}"
                cases:
                  1:
                    - id: 2-1-1_switch-number-1
                      type: io.kestra.plugin.core.debug.Return
                      format: "{{ parents[0].taskrun.value }}"
                  2:
                    - id: 2-1-1_switch-number-2
                      type: io.kestra.plugin.core.debug.Return
                      format: "{{ parents[0].taskrun.value }} {{ parents[1].taskrun.value }}"
  - id: 2_end
    type: io.kestra.plugin.core.debug.Return
    format: "{{ task.id }} > {{ taskrun.startDate }}"

As you can see, the parent will give direct access to the first parent output and the value of the current one, while the parents[INDEX] lets go you deeper down the tree.

In the task 2-1-1_switch-number-2:

  • {{ taskrun.value }}: mean the value of the task 2-1-1_switch
  • {{ parents[0].taskrun.value }} or {{ parent.taskrun.value }}: mean the value of the task 2-1_each
  • {{ parents[1].taskrun.value }}: mean the value of the task 2-1_switch
  • {{ parents[2].taskrun.value }}: mean the value of the task 2_each

vars

firstDefined First defined variables

Return the first defined variables or throw an exception if no variables are defined.

handlebars
{{ firstDefined outputs.task1.uri outputs.task2.uri }}

eval Evaluate a handlebars expression

Evaluate a handlebars expression at runtime based on the whole context.

Mostly useful for Lookup in current child's tasks tree and dynamic tasks.

handlebars
{{ eval 'outputs.first.[{{taskrun.value}}].value' }}

firstDefinedEval First defined evaluation

First defined evaluates a handlebars expression at runtime based on the whole context or throws an exception if no variables are defined.

Mostly useful for Lookup in current child's tasks tree and dynamic tasks.

handlebars
{{ firstDefined 'outputs.first.value' 'outputs.first.[{{taskrun.value}}].value' }}

get get an element for an array or map by key

handlebars
   {{ get object ["key"] }}
  • get on object type map, the key at key
  • get on object type array, the index at key

Mostly useful for Lookup in current child's tasks tree and dynamic tasks.

handlebars
{{ get outputs 'first' }}

Was this page helpful?