Reference for require("template") in goja-text xgoja runtimes.
Use require("template") when JavaScript needs Go text/template or html/template rendering with Go-backed builders and result objects.
The module exposes Go-backed objects. JavaScript therefore uses exported Go method and field names such as Name, Funcs, MissingKey, Parse, Render, Text, TemplateName, and Bytes.
const template = require("template");
Creates a Go-backed text/template builder.
const set = template.text()
.Name("greeting")
.Funcs("sprig", "glazed")
.MissingKey("error")
.Parse("Hello {{ .Name | upper }}");
console.log(set.Render({ Name: "intern" }).Text);
Creates a Go-backed html/template builder. HTML mode uses Go's contextual escaping rules.
const result = template.html()
.Parse('<p>{{ .Name }}</p><a href="{{ .URL }}">open</a>')
.Render({ Name: '<Ada>', URL: 'javascript:alert(1)' });
console.log(result.Text);
Parses and renders a text template in one call. This is convenience sugar over template.text().Parse(source).Render(data).
Parses and renders an HTML template in one call. This is convenience sugar over template.html().Parse(source).Render(data).
Name(name) — set the root template name.Funcs(...names) — choose helper presets. Supported names are "sprig", "glazed", and "none".MissingKey(policy) — choose Go template missing-key behavior: "default", "invalid", "zero", or "error".Delims(left, right) — set custom delimiters.JSFunc(name, fn) — register a synchronous JavaScript function as a template helper. Function names must match [A-Za-z_][A-Za-z0-9_]*.Validate() — return { Valid, Errors } without parsing.BuildConfig() — return a frozen Go-backed config or throw if invalid.Parse(source) — parse source using the current builder name.ParseNamed(name, source) — parse source as a named template.Mode — "text" or "html".Name — default template name.Render(data?) — execute the default template.RenderString(data?) — execute and return only the rendered string.RenderTemplate(name, data?) — execute a named template from the set.Templates() — list template metadata.Lookup(name) — return metadata for one named template or undefined/null.Text — rendered output.TemplateName — executed template name.Mode — "text" or "html".Bytes — byte length of Text.sprig and glazed.error for automation safety.JSFunc are synchronous and run during template execution.JSFunc remain untrusted and are escaped by html/template.