text/template
text/template
component: Parse templates using text/template (opens new window). It is used in scenarios such as message format transformation, content templating, and data adaptation. It supports a rich set of template syntax and custom function extensions.
# Configuration
Field | Type | Description | Default Value |
---|---|---|---|
template | string | Template content or template file path. Use the prefix file: to indicate a file path, such as file:/path/to/tpl.txt | None |
Supported template variables:
.id
- Message ID.ts
- Message timestamp (in milliseconds).data
- Raw message content.msg
- Message body object (when of JSON type, you can access fields with.msg.field
).metadata
- Message metadata object.type
- Message type.dataType
- Data type
Template example:
{{ .msg.name }} - Retrieve the name field from the message
{{ .metadata.deviceType }} - Retrieve the device type from metadata
{{ .type }} - Retrieve the message type
{{ .ts }} - Retrieve the message timestamp
{{ if gt .msg.temperature 30 }}High Temperature{{ else }}Normal{{ end }} - Conditional judgment
{{ range .msg.items }}{{ .name }},{{ end }} - Iterate over an array
{{ printf "%.2f" .msg.value }} - Format a number
{{ .msg.name | upper }} - Convert to uppercase
{{ .msg.content | replace "old" "new" }} - Replace text
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# Configuration example
{
"id": "s1",
"type": "text/template",
"name": "Template Transformation",
"configuration": {
"template": "type:{{ .type}}"
}
}
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
Edit this page on GitHub (opens new window)
Last Updated: 2025/01/09, 11:45:29