Documentation
¶
Overview ¶
Package template provides package-agnostic text template rendering.
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 ¶
This section is empty.
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") )
Functions ¶
func Render ¶
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 ¶
This section is empty.