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 ¶
const ID = "template"
Variables ¶
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") )
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 Render ¶ added in v0.23.0
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.