Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

A Template Transformation converts a given data structure in another format using a template.

This template will be parsed by a template engine which applies a given model to it by interpolating variables inside the template with data from the model.

Since a template transformation is a very clean and flexible approach it can often be the right choice to convert from one format to another.

It is often used to convert from JSON to any other text-based format like XML, CSV or plain text.

The transform.ftl command

The transformer command transform.ftl uses the template engine FreeMarker in order to apply a transformation on a given model using a given template.

...

Below you can find a simple example how this could look like in a pipeline with model and template defined as inline values:

Code Block
languageyaml
pipeline:

  - transform.ftl:
      model: {
          "firstName": "Max", 
          "lastName": "Smith"
        }
      template: |
        Hello ${firstName} ${lastName}!

...

Here is an example which loads the model from the property store and the template from drive:

Code Block
languageyaml
pipeline:

  - transform.ftl:
      model: $uri:property:global/app/myapp/data/person@value
      template: $uri:drive:/templates/person.ftl

It is also possible to directly access the vars, headers and body scope inside the template. In this case no model must be passed:

Code Block
languageyaml
vars:
  firstName: Max,
  lastName: Smith
pipeline:

  - transform.ftl:
      template: |
        Hello ${vars.firstName} ${vars.lastName}!

...