Skip to content

Commit

Permalink
doc: Add example how to parse pebble in variables (#591)
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-geller authored Oct 18, 2023
1 parent 792b9a4 commit 444c259
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions content/docs/05.developer-guide/03.variables/01.index.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,40 @@ The `Return` task has an output attribute `value` which is used by the `log-both
In the `log-both-variables` task, you can see two ways to access task outputs: the dot notation (`outputs.firstExample`) and the subscript notation (`outputs['second-example']`). The subscript notation must be used when a variable contains a special character, such as `-` that is a Pebble reserved character.
::

## Pebble templating
Pebble templating offers various ways to process variables, see:

## Pebble templating: example

The example below will parse the Pebble expressions within the `variables` based on the `inputs` and `trigger` values. Both variables use the [Null-Coalescing Operator](02.basic-usage.md#null-coalescing-operator) to use the first non-null value.

Here, the first variable `trigger_or_yesterday` will evaluate to a `trigger.date` if the flow runs on schedule. Otherwise, it will evaluate to the yesterday's date by using the `execution.startDate` minus one day.

The second variable `input_or_yesterday` will evaluate to the `mydate` input if it's provided. Otherwise, it will evaluate to the yesterday's date — again, using the `execution.startDate` and subtracting one day with the help of the `dateAdd` function.

```yaml
id: vars_example
namespace: dev
inputs:
- name: mydate
type: DATETIME
required: false
variables:
trigger_or_yesterday: "{{ trigger.date ?? (execution.startDate | dateAdd(-1, 'DAYS')) }}"
input_or_yesterday: "{{ inputs.mydate ?? (execution.startDate | dateAdd(-1, 'DAYS')) }}"
tasks:
- id: yesterday
type: io.kestra.core.tasks.log.Log
message: "{{ vars.trigger_or_yesterday }}"
- id: input_or_yesterday
type: io.kestra.core.tasks.log.Log
message: "{{ vars.input_or_yesterday }}"
```


## Pebble templating: deep dive
Pebble templating offers a myriad of ways to process variables. For a deep dive, check the following section:

<ChildTableOfContents :max="1" />

0 comments on commit 444c259

Please sign in to comment.