Step Operation - Template
Template
template is an intermediate step that creates a data resource from a template.
How it works
- receives as arguments:
- a template
- a map of data (known as the data model or context)
- and outputs a result (known as the target)
The number, the type of output and the data model depends on the execution_mode.
Cli
The template operation is also available as cli command.
Execution Mode
The execution mode define how the template operation proceeds.
There are 3 execution modes that depends on:
- the granularity:
- record: 1 record, 1 target output
- resource: 1 resource, 1 target output
- the processing type:
- cumulative: N data model, 1 output (Each record is passed to build and get a json tree structure)
- map: 1 data model, 1 output
| Execution Mode | Granularity | Processing Cardinality | Template Media Type Supported | Engine Supported |
|---|---|---|---|---|
| Record Mode | Record | 1-to-1 | All | All |
| Resource Mode | Resource | 1-to-1 | All | All |
| Resource Cumulative Mode | Resource | n-to-1 | Json | Native |
Record Mode
If the granularity of execution is record, each record of an input will produce 1 result (1 target)
The data model passed to the template is build with:
- the columns name and their scalar value
- and optionally extra variables with a list of map data via the template-model-variables
Example:
column1: value1
column2: value2
extra-variable-name:
# row 1
- column1: value1
column2: value2
...
# row 2
- column1: value1
column2: value2
...
Resource Mode
If the granularity of execution is resource, each input resource will produce 1 result (1 target)
The data model is build with each record of the input.
Example:
# record 1
- column1: value1
column2: value2
# record 2
- column1: value1
column2: value2
Resource Cumulative Mode
In a resource cumulative mode, each record of a resource is used to build a tree structure.
The engine gets the records one by one and outputs at the end 1 result.
Example of data model:
# record N
column1: value1
column2: value2
As of today, only json template with the native engine supports this mode. Tabulify HowTo - How to create JSON file(s) from Tabular data with a JSON template
Arguments
The template operations accept the following arguments.
| Name | Default | Description |
|---|---|---|
| template-selector | a data selector that selects templates data resources | |
| template-selectors | a list of data selectors that selects templates data resources | |
| template-inline | a inline template with the following properties: * media-type: the media-type of the template * content: the template text * logical-name: optional logical-name for template matching. Default to anonymous |
|
| template-email | false | if true, the html template is an email template. The css rules will be in-lined for html template. If you use bootstrap, the bootstrap email css stylesheet is used instead. |
| processing-type | map cumulative (JSON) | How the data models are applied to the template engine cumulative: N data model, 1 output map: 1 data model, 1 output |
| engine | native | the templating engine |
| granularity | record | defines the granularity of the execution * record: the template will be processed for each record (default) * resource: the template will be processed on all records (only available for a json template) |
| model-variables | A list of map variables added to the model. See model-variables for the definition | |
| target-column-name | ${template_media_subtype} | The column name that stores the template output in a template string format |
| target-data-uri | see target-data-uri | A template data uri that defines the data uri of the templating results |
| target-media-type | Default to the template media type | |
| target-data-def | An optional data definition | |
| target-kind | template-outputs | Define the kind of target template-outputs: the output of the template engine, enriched-inputs: the output of the template engine are stored in a column of the input data-model: the data model in JSON format |
| output-type | targets | the output may be * targets * inputs |
model-variables
model-variables is a list of variable definition. Each element contains the following attributes:
| Name | Mandatory | Definition |
|---|---|---|
| name | true | the variable name |
| data-uri | true | a data uri or runtime data uri |
engine
The engine is the process that is responsible to transform a template in a document.
Tabulify supports the following value as engine:
- native (default) - the built-in tabulify engine
- thymeleaf - the the thymeleaf engine (natural template)
- pebble - the pebble engine (ninja syntax)
template-data-uri
The default template data uri is:
${input_logical_name}_${template_name}@memory
which means that the output will:
- get as name
- the logical name of its input
- and the name of its template
- be stored in memory
Template Match
If the operation has defined:
- only one template, the template will be applied to all input data resource.
- multiple templates, the template will be the template that has the same logicalName than the input data resource
Syntax
This operation is a intermediate pipeline operation
- Template Selectors
- operation: "template"
arguments:
template-selectors:
- pattern@connection
- pattern2@connection2
- Inline Json Template
- operation: "template"
arguments:
template-inline:
media-type: json
content: |
{
"${group}": {
"${item_code}": {
"price": "${price}",
"description": "${description}"
}
}