template

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 13 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package template contains the template node implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderMustache added in v0.7.0

func RenderMustache(tpl string, input nodestore.MessageInterface, host nodebase.NodeHost, workflowID, nodeID string, jsonEscape bool) (string, error)

RenderMustache renders a mustache template the way Node-RED does: the message itself (payload + every metadata property) is the mustache context; {{env.X}}, {{flow.X}} and {{global.X}} tags are resolved against the host before rendering — the two-phase NodeContext behaviour, where context tokens are pre-resolved and message properties take precedence. host may be nil — context tags then resolve to empty. jsonEscape applies Node-RED's JSON-mode string escaping to the message context. Shared by nodes that template user text against the message (e.g. ai-request).

Types

type TemplateConfig

type TemplateConfig struct {
	// Template is the template source; when empty, a runtime
	// msg.template metadata property supplies it (Node-RED parity).
	Template string `json:"template"`
	// Syntax: "mustache" (default, Node-RED parity), "gotemplate"
	// (extension-only Go text/template against msg.payload), or "plain"
	// (no rendering — the template text passes through verbatim).
	Syntax string `json:"syntax"`
	// Field is the target property: "payload" (default) or a dotted
	// message-property path when FieldType is "msg", or a context key
	// (optionally "#:(store)::key") when FieldType is flow|global.
	Field string `json:"field"`
	// FieldType: "msg" (default), "flow" or "global" — where the
	// rendered value is written.
	FieldType string `json:"fieldType"`
	// Output: "str" (default), "json" (parse the rendered text into
	// JSON), or "yaml" (parse into a YAML value).
	Output string `json:"output"`
	// Format is the legacy engine alias: "json" → Output "json",
	// "text" → Output "str". Ignored when Output is set.
	Format string `json:"format"`
}

TemplateConfig holds configuration for the template node, mirroring Node-RED's template node fields plus the extension-only gotemplate syntax and the legacy Format alias.

type TemplateNode

type TemplateNode struct {
	*nodebase.BaseNode
	// contains filtered or unexported fields
}

TemplateNode renders a Mustache template against the message (Node-RED parity), with Go text/template kept as a extension-only syntax option.

func NewTemplateNode

func NewTemplateNode(node nodestore.NodeInterface, config *TemplateConfig, host nodebase.NodeHost) *TemplateNode

NewTemplateNode creates a new template node. host may be nil — the {{flow.X}} / {{global.X}} / {{env.X}} context tags then resolve to empty and flow/global field targets are dropped.

func (*TemplateNode) Execute

Execute renders the template and writes the result to the configured target.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL