Templates
What is a template?
A template is an advanced formula used in a Rules Engine action to compute the value of a target field.
Instead of simply copying a value from another field or setting a static default value, a template lets you:
- Combine several fields together
- Clean or normalize text (uppercase, lowercase, trim, replace, etc.)
- Perform mathematical operations
Templates use the Twig template engine syntax, extended with Product-Live specific functions. These custom functions are only available inside Product-Live — they will not work in external Twig tools.
When should I use a template?
If a simple "copy from another field" or "set a default value" is enough, prefer these actions. Use templates when you need logic or transformation.
- Concatenate fields : build a product label from brand + title.
- Normalize text : ensure a title is always uppercase or trimmed.
- Compute a number : convert mm to cm, compute a discount, add two measures.
Twig syntax basics
Twig uses two kinds of delimiters:
{{ ... }}: outputs the result of an expression (the value written into the target field){% ... %}: control logic (conditions, loops, variable assignments, etc.)
twig
{{ targetItem.fields.TITLE.value.data }}1
twig
{% if targetItem.fields.BRAND.value.data == 'ACME' %}
{{ 'ACME PRODUCT' }}
{% else %}
{{ targetItem.fields.BRAND.value.data }} - {{ targetItem.fields.TITLE.value.data }}
{% endif %}1
2
3
4
5
2
3
4
5
Field values are accessed via the item structure — see Reference item and Product-Live functions.
For more details about the Twig syntax, see the Twig documentation.
Useful Twig filters
| Filter | Description |
|---|---|
lower | Converts a string to lowercase |
upper | Converts a string to uppercase |
trim | Trims whitespace from the beginning and end of a string |
replace | Replaces substrings inside a string |
date | Formats a date to a given format |
merge | Merges two arrays |
filter | Filters an array using a condition |
For the full list of available filters, see the Twig documentation.
TIP
Always use default('') before applying a filter to avoid errors on null values:
twig
{{ targetItem.fields.TITLE.value.data | default('') | trim | upper }}1
Without default(''), if the TITLE field is empty or missing, Twig receives null and trim throws an error. With default(''), it receives an empty string and continues safely.
Product‑Live functions
Product-Live extends Twig with custom functions and variables. Their availability depends on the template engine used.
| Function / Variable | Description | Engine |
|---|---|---|
targetItem | The current item being processed | twig.2 |
sourceItem | The source item | twig.2 |
base64_encode() | Encode a string into a Base64 value | twig.1, twig.2 |
base64_decode() | Decode a Base64 string into a readable string | twig.1, twig.2 |
source() | Access the value of a property on a source item | twig.1 |
target() | Access the value of a property on the current item | twig.1 |
TIP
We recommend using twig.2 for new templates. Use targetItem.fields.FIELD_KEY.value.data and sourceItem.fields.FIELD_KEY.value.data to access field values directly. See Reference item for the full item structure.
Use twig.1 only for existing templates that cannot be migrated yet.
targetItem and sourceItem
targetItem and sourceItem give access to the full structure of an item.
- In a mapping context:
sourceItemis the source item,targetItemis the item being updated. - In a formula context: both point to the same item : the one being updated.
twig
{{ targetItem.fields.FIELD_KEY.value.data }}
{{ sourceItem.fields.FIELD_KEY.value.data }}1
2
2
twig
{{ targetItem | json_encode | raw }}1
For the full item structure, see Reference item.
base64_encode() and base64_decode()
These functions are useful when you need to build URLs or encoded filters.
twig
{{ base64_encode("[{\"fieldKey\":\"EAN\",\"operator\":\"contains\",\"criteria\":{\"string\":\"2000099919335\"}}]") }}1
twig
{{ base64_decode("e1wiZmllbGRLZXlcIjpcIkVBTlwiLFwib3BlcmF0b3JcIjpcImNvbnRhaW5zXCIsXCJjcml0ZXJpYVwiOntcInN0cmluZ1wiOlwiMjAwMDA5OTkxOTMzNVwifX0=") }}1
source() and target()
WARNING
These functions are only available in twig.1. We recommend using sourceItem and targetItem in twig.2 instead.
source() reads a field value from the source item. target() reads a field value from the target item being updated.
twig
{# Read a simple field value #}
{{ source('TITLE') }}
{# Read the key of an option or classification #}
{{ source('COLOR', 'key') }}
{# Read the title of an option or classification #}
{{ source('COLOR', 'title') }}
{# Read the localized title of an option or classification #}
{{ source('COLOR', 'title-local', 'fr') }}1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
twig
{# Read a simple field value #}
{{ target('TITLE') }}
{# Read the key of an option or classification #}
{{ target('COLOR', 'key') }}
{# Read the title of an option or classification #}
{{ target('COLOR', 'title') }}
{# Read the localized title of an option or classification #}
{{ target('COLOR', 'title-local', 'en') }}1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
INFO
In a mapping context, if an item has multiple source items, source() returns the value from the most recently updated one.
Reference Item
The following JSON represents a typical item as seen by the template engine. The examples in this page use fields from this item.
json
{
"fields": {
"EAN": {
"key": "EAN",
"type": "IDENTIFIER",
"value": {
"data": "8710103533825"
}
},
"TITLE": {
"key": "TITLE",
"type": "SINGLE-LINE-TEXT",
"value": {
"data": "Top Robot Mower"
}
},
"DESCRIPTION": {
"key": "DESCRIPTION",
"type": "LONG-TEXT",
"value": {
"data": "The ideal model for discovering the world of lawnmowers. Lightweight and agile, with its 146cc engine, this mower will be your ideal partner for lawn care."
}
},
"WEB_DESCRIPTION": {
"key": "WEB_DESCRIPTION",
"type": "LONG-TEXT",
"value": {
"data": "The ideal model for discovering the world of lawnmowers. <b>Lightweight</b> and <b>agile</b>, with its 146cc engine, this mower will be your ideal partner for lawn care."
}
},
"BRAND": {
"key": "BRAND",
"type": "SINGLE-SELECT",
"value": {
"data": "SUPPLIER-X"
}
},
"ADDED_VALUE": {
"key": "ADDED_VALUE",
"type": "MULTIPLE-SELECT",
"value": {
"data": [
"SIMPLE",
"EFFICIENT"
]
}
},
"BATTERY": {
"key": "BATTERY",
"type": "MULTIPLE-SELECT-QUANTIFIED",
"value": {
"data": [
{
"key": "AA",
"quantity": 2
},
{
"key": "AAA",
"quantity": 4
}
]
}
},
"CONNECTOR": {
"key": "CONNECTOR",
"type": "MULTIPLE-SELECT-QUANTIFIED-WITH-COMMENT",
"value": {
"data": [
{
"key": "USB",
"quantity": 2,
"comment": "3.2"
},
{
"key": "USB",
"quantity": 1,
"comment": "C"
}
]
}
},
"INSTRUCTIONS": {
"key": "INSTRUCTIONS",
"type": "ATTACHMENT",
"value": {
"data": {
"hash": "4214f8cd460bdbec6a936c6088d0a73140c89c9dd042e123f0cbd3e94c6144ff",
"filename": "manual.pdf"
}
}
},
"FRONT": {
"key": "FRONT",
"type": "IMAGE",
"value": {
"data": {
"hash": "4214f8cd460bdbec6a936c6088d0a73140c89c9dd042e123f0cbd3e94c6144ff",
"filename": "front-image.jpg"
}
}
},
"PRICE": {
"key": "PRICE",
"type": "NUMBER",
"value": {
"data": 329.99
}
},
"DELIVERY_DATE": {
"key": "DELIVERY_DATE",
"type": "DATE",
"value": {
"data": "2026-02-20"
}
},
"MARKETING_DATE": {
"key": "MARKETING_DATE",
"type": "DATE-TIME",
"value": {
"data": "2026-02-20T11:00:58.000Z"
}
},
"TITLE": {
"key": "TITLE",
"type": "COMPOSITE",
"data": [
{
"position": 0,
"id": "01KHXA9V416XTX030VAFKHMXYY",
"data": {
"LOCAL_LANGUAGE": {
"key": "LOCAL_LANGUAGE",
"type": "SINGLE-SELECT",
"value": {
"data": "FRA"
}
},
"LOCAL_TITLE": {
"key": "LOCAL_TITLE",
"type": "SINGLE-SELECT",
"value": {
"data": "Robot Tondeuse Top Surface de travail maximale de 3000 m² ou plus"
}
},
}
},
{
"position": 1,
"id": "01KHXA9WXNMQXFESH90A23NPVC",
"data": {
"LOCAL_LANGUAGE": {
"key": "LOCAL_LANGUAGE",
"type": "SINGLE-SELECT",
"value": {
"data": "ENG"
}
},
"LOCAL_TITLE": {
"key": "LOCAL_TITLE",
"type": "SINGLE-SELECT",
"value": {
"data": "Top Robot Mower Maximum working area of 3000 m² or more"
}
},
}
}
]
},
},
"parent": null,
"parentId": null,
"children": null,
"object": "item",
"id": "186383",
"createdAt": "2026-01-29T09:28:53.000Z",
"updatedAt": "2026-02-03T16:32:52.000Z",
"itemMetadata": {
"createdAt": "2026-01-29T09:28:53.000Z",
"updatedAt": "2026-02-03T16:32:52.000Z",
"tableId": "319",
"tableKey": "PRODUCTS_MONO_COMPOSITE",
"tableOwnerAccountId": "4",
"levelId": "336",
"levelKey": "PRODUCT",
"partitionId": "537"
}
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
Twig examples
twig
{{ targetItem.fields.BRAND.value.data }} - {{ targetItem.fields.TITLE.value.data }}1
twig
{{ targetItem.fields.TITLE.value.data | default('') | trim | upper }}1
twig
{{ targetItem.fields.PRICE.value.data * 1.20 }}1
Testing your templates
You can use twig.stapps.io to test your Twig syntax outside of Product-Live.
- Paste the JSON input you want to use (for example a simplified
sourceItem+targetItem) - Paste your Twig template
- Click Render to see the result
WARNING
Product-Live specific functions and variables (targetItem, sourceItem, base64_encode(), base64_decode()) are not available on this tool. Use it only to test standard Twig syntax.
XML configuration
When you configure a template via Data Factory, the Twig expression is wrapped in a <Template> node inside a SET_TEXT or SET_NUMBER action. To deploy templates to your tables, use the table-import-schema task.
The Twig expression must be wrapped in <![CDATA[ ... ]]> to prevent the XML parser from interpreting special characters (such as <, >, &) as XML markup.
Attributes
| Attribute | Values | Default | Description |
|---|---|---|---|
engine | twig.1 / twig.2 | twig.1 | Selects the template engine used to execute the expression. |
trim-spaces | true / false | false | If true, leading and trailing spaces are removed from the output before it is written into the target field. Recommended for identifiers and single-line text fields. |
precision | integer | 2 | Number of decimal places to keep in the final result. Only applicable to SET_NUMBER actions. |
round | UP, DOWN, CEILING, FLOOR, HALF_UP, HALF_DOWN | HALF_UP | Rounding mode to apply. See Rounding methods. Only applicable to SET_NUMBER actions. |
WARNING
The default engine is twig.1. We recommend explicitly setting engine="twig.2" for new templates. See Template engines for details.
xml
<Action type="SET_TEXT">
<Template engine="twig.2">
<![CDATA[{{ targetItem.fields.TITLE.value.data | default('') | upper }}]]>
</Template>
</Action>1
2
3
4
5
2
3
4
5
xml
<Action type="SET_TEXT">
<Template trim-spaces="true" engine="twig.2">
<![CDATA[{{ targetItem.fields.TITLE.value.data | default('') | upper }}]]>
</Template>
</Action>1
2
3
4
5
2
3
4
5
xml
<Action type="SET_NUMBER">
<Template precision="2" round="HALF_UP" engine="twig.2">
<![CDATA[{{ targetItem.fields.PRICE.value.data * 1.20 }}]]>
</Template>
</Action>1
2
3
4
5
2
3
4
5
Template engines
Engines are configured per rule, it is possible to mix twig.1 and twig.2 on the same table.
twig.1 (default, legacy)
- Supports standard Twig syntax and filters.
- Adds Product-Live specific functions:
source(),target(),base64_encode(),base64_decode(). - Use only for existing templates that cannot be migrated yet.
xml
<Action type="SET_TEXT">
<Template engine="twig.1">
<![CDATA[{{ source("TITLE") | default('') | upper }}]]>
</Template>
</Action>1
2
3
4
5
2
3
4
5
twig.2 (recommended)
- Supports standard Twig syntax and filters.
- Adds Product-Live specific variables and functions:
targetItem,sourceItem,base64_encode(),base64_decode(). - Lighter and faster to execute — recommended for new templates and tables with a large number of rules.
xml
<Action type="SET_TEXT">
<Template engine="twig.2">
<![CDATA[{{ targetItem.fields.TITLE.value.data | default('') | upper }}]]>
</Template>
</Action>1
2
3
4
5
2
3
4
5
Examples
xml
<Field key="TITLE" source-table="products">
<Rule priority="1">
<Action type="SET_TEXT">
<Template trim-spaces="true" engine="twig.2">
<![CDATA[
{{ targetItem.fields.BRAND.value.data }} - {{ targetItem.fields.TITLE.value.data }}
]]>
</Template>
</Action>
</Rule>
</Field>1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
xml
<Field key="TITLE" source-table="products">
<Rule priority="1">
<Action type="SET_TEXT">
<Template trim-spaces="true" engine="twig.2">
<![CDATA[
{{ targetItem.fields.TITLE.value.data | default('') | trim | upper }}
]]>
</Template>
</Action>
</Rule>
</Field>1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
xml
<Field key="PRICE_VAT" source-table="products">
<Rule priority="1">
<Action type="SET_NUMBER">
<Template precision="2" round="HALF_UP" engine="twig.2">
<![CDATA[
{{ targetItem.fields.PRICE.value.data * 1.20 }}
]]>
</Template>
</Action>
</Rule>
</Field>1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
Limits
- The output of a template is limited to 1 000 characters. If the output exceeds this limit, the value is not written and an error is raised.
- A template can read from a maximum of 20 source fields. If more fields are referenced, the template will not execute and an error is raised. If you need more, consider using intermediate fields to split the computation.
- Template execution has a timeout. If the expression takes too long to evaluate, the execution is stopped and an error is raised.
- If a template is invalid or produces an error, the value is not updated (the task continues for other items).
TIP
For best performance and reliability:
- Keep templates as simple as possible.
- Avoid heavy loops on large sets of children when you can express the same logic with several simpler rules.