RuleGo RuleGo
🏠Home
  • Quick Start
  • Rule Chain
  • Standard Components
  • Extension Components
  • Custom Components
  • Visualization
  • RuleGo-Server
  • RuleGo-MCP-Server
  • AOP
  • Trigger
  • Advanced Topics
  • Performance
  • Standard Components
  • Extension Components
  • Custom Components
  • Components Marketplace
  • Overview
  • Quick Start
  • Routing
  • DSL
  • API
  • Options
  • Components
🔥Editor (opens new window)
  • RuleGo Editor (opens new window)
  • RuleGo Server (opens new window)
  • Github (opens new window)
  • Gitee (opens new window)
  • Changelog (opens new window)
  • English
  • 简体中文
🏠Home
  • Quick Start
  • Rule Chain
  • Standard Components
  • Extension Components
  • Custom Components
  • Visualization
  • RuleGo-Server
  • RuleGo-MCP-Server
  • AOP
  • Trigger
  • Advanced Topics
  • Performance
  • Standard Components
  • Extension Components
  • Custom Components
  • Components Marketplace
  • Overview
  • Quick Start
  • Routing
  • DSL
  • API
  • Options
  • Components
🔥Editor (opens new window)
  • RuleGo Editor (opens new window)
  • RuleGo Server (opens new window)
  • Github (opens new window)
  • Gitee (opens new window)
  • Changelog (opens new window)
  • English
  • 简体中文

广告采用随机轮播方式显示 ❤️成为赞助商
  • Quick Start

  • Rule Chain

  • Standard Components

    • Standard Components Overview
    • filter

    • action

    • transform

      • jsTransform
      • exprTransform
      • metadataTransform
      • text/template
        • Configuration
        • Configuration example
    • external

    • flow

  • Extension Components

  • Custom Components

  • Components marketplace

  • Visualization

  • AOP

  • Trigger

  • Advanced Topic

  • RuleGo-Server

  • FAQ

  • Endpoint Module

  • Support

目录

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

# Configuration example

{
  "id": "s1",
  "type": "text/template",
  "name": "Template Transformation",
  "configuration": {
    "template": "type:{{ .type}}"
  }
}
1
2
3
4
5
6
7
8
Edit this page on GitHub (opens new window)
Last Updated: 2025/04/02, 01:29:50
metadataTransform
restApiCall

← metadataTransform restApiCall→

Theme by Vdoing | Copyright © 2023-2025 RuleGo Team | Apache 2.0 License

  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式