template

package
v0.25.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package template provides a reusable Go text-template renderer and exposes it to Flow as the template.render action.

Typical use:

template.render @{ template: "Hello {{.name}}", variables: { name: "Flow" } }

Package template implements text rendering for the template extension.

It uses Go's standard text/template syntax and never executes rendered text as a command. The renderer returns plain text; it does not HTML-escape output.

Index

Examples

Constants

View Source
const ID = "template"

Variables

View Source
var (
	// ErrParse identifies invalid template syntax or an unknown template function.
	ErrParse = errors.New("template parse error")
	// ErrExecute identifies a failure while evaluating a parsed template,
	// including a reference to a missing map key.
	ErrExecute = errors.New("template execution error")
)
View Source
var RenderAction = action.New("template.render", func(_ context.Context, req RenderRequest) (string, error) {
	result, err := Render(req.Template, req.Variables)
	if err != nil {
		return "", xerr.BadRequest(err.Error())
	}
	return result, nil
}).Description("Render a text template with supplied variables").
	Example(RenderRequest{
		Template:  "Hello {{.name}}",
		Variables: map[string]any{"name": "Flow"},
	}).Build()

RenderAction exposes the package-agnostic renderer to Flow workflows.

Functions

func Bundle

func Bundle(_ map[string]string) core.Bundle

Bundle exposes the template.render action to Flow.

func Library

func Library() action.Library

Library returns the action library without requiring registry lookup.

func Render added in v0.23.0

func Render(source string, variables map[string]any) (string, error)

Render evaluates source with variables as the template's root data.

Templates use Go text/template syntax, for example `Hello {{.name}}`. A missing map key is an error (rather than silently rendering an empty value). Extra keys in variables are allowed and ignored when unused. A nil variables map behaves like an empty map. On any error, Render returns an empty string, never partial output.

Values are inserted as text and are not parsed again as template source. Render does not execute shell commands and does not HTML-escape its result.

Example
got, err := Render("Hello {{.name}} — {{.literal}}", map[string]any{
	"name":    "srcpack",
	"literal": "$(this remains text)",
})
if err != nil {
	fmt.Println(err)
	return
}
fmt.Println(got)
Output:
Hello srcpack — $(this remains text)

Types

type RenderRequest

type RenderRequest struct {
	Template  string         `json:"template"  cli:"template"`
	Variables map[string]any `json:"variables" cli:"variables"`
}

RenderRequest is the input shape for the template.render Flow action.

Jump to

Keyboard shortcuts

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