Skip to content
Docs
Modules
template

template

String templating functionality.

Builtins

render

Function signature
render(data object, template string) string

Returns the rendered template as a string. It includes all the sprig lib functions. You can access environment variables from the template under .Env and the passed values will be available under .Values in the template

If compiled with -tags k8s (opens in a new tab), it also includes a k8sLookup function to get values from k8s objects.

Example
>>> fetch("http://ipinfo.io").json() | render("You are in {{ .Values.city }}, region {{ .Values.region }} in {{ .Values.timezone }}")
"You are in Dublin, region Leinster in Europe/Dublin"

Functions

new

Function signature
new(name string) template

Instanciates a new template object with the given name.

Example
tpl :=  template.new("test")
tpl.delims("{%", "%}")

add

Function signature
add(name string, template string)

Adds a named template to the template object

Example
tpl.add("ipinfo", "You are in {% .city %}, region {% .region %} in {% .timezone %}")

execute_template

Function signature
execute_template(data object, name string) string

Renders the given named template into a string.

Example
>>> tpl.execute_template(fetch("http://ipinfo.io").json(), "ipinfo")
"You are in Dublin, region Leinster in Europe/Dublin"

parse

Function signature
parse(template string)

Parses a template into the template object

Example
tpl.parse("You are in {% .city %}, region {% .region %} in {% .timezone %}")

execute

Function signature
execute(data object) string

Renders the templates into a string.

Example
>>> tpl.execute(fetch("http://ipinfo.io").json())
"You are in Dublin, region Leinster in Europe/Dublin"