std/template
On this page
Index
- type
TemplateErr- method
TemplateErr.display
- method
- type
TemplateFn - type
Template- method
Template.add - method
Template.missing_key - method
Template.render - method
Template.render_named
- method
- type
Parsed - fn
parse - fn
parse_html - fn
html - fn
css - fn
js - fn
jsstr - fn
url - fn
attr - fn
srcset
Types
TemplateErr
struct TemplateErr {
msg: Str
}A parse or execution error, with Go’s text
(template: t:1: function "nope" not defined).
TemplateErr.display
fn (e: TemplateErr) display() -> StrThe message, Go’s text (decision 0358).
TemplateFn
type TemplateFn = fn(List[json.Value]) -> json.Value ! StrA template function (FuncMap, decision 0408): its arguments as the
executor’s values, its result a value the template prints or passes
on (escaped by the html mode’s context); Err text is the call’s
error, error calling NAME: text. Pure: a function with effects
cannot be called from a render.
Template
struct Template {
name: Str
sources: List[(Str, Str)]
left: Str = "{{"
right: Str = "}}"
missing_key_error: Bool = false
funcs: Map[Str, TemplateFn] = {}
html: Bool = false
parsed: Parsed
}A set of named templates (template.Template and its associated
templates): each name’s source, in the order added, the action
delimiters, and whether a missing object key is an error
(missingkey=error) rather than <no value>.
Template.add
fn (t: Template) add(name: Str, src: Str) -> Template ! TemplateErrAnother named template in the set (t.New(name).Parse(src)).
Template.missing_key
fn (t: Template) missing_key(error: Bool) -> TemplateThe set with Option(“missingkey=error”) (true) or the default.
Template.render
fn (t: Template) render(data: json.Value) -> Str ! TemplateErrExecute: the output of the template named t.name with data.
Template.render_named
fn (t: Template) render_named(name: Str, data: json.Value) -> Str ! TemplateErrExecuteTemplate: the output of the template name of the set.
Parsed
struct Parsed {}The parsed trees of a Template (opaque).
Functions
parse
fn parse(name: Str, src: Str, left: Str = "{{", right: Str = "}}", funcs: Map[Str, TemplateFn] = {}) -> Template ! TemplateErrtemplate.New(name).Delims(left, right).Parse(src): the template, or
Go’s parse error. {{define}} blocks become templates of the set.
parse_html
fn parse_html(name: Str, src: Str, left: Str = "{{", right: Str = "}}", funcs: Map[Str, TemplateFn] = {}) -> Template ! TemplateErrhtml/template’s New(name).Parse(src): parse with contextual
autoescaping (decision 0408). The escaping errors (a template that
ends inside a tag, branches ending in different contexts, an action
in an ambiguous URL part, a predefined escaper in a pipeline) are
render’s, as Go reports them on Execute.
html
fn html(s: Str) -> json.ValueTrusted content for the html mode (decision 0408; Go’s template.HTML, CSS, JS, JSStr, URL, HTMLAttr, Srcset): a json.Value only these make, passed through unescaped in its own context, escaped as text in any other, and the plain string to every other reader.
css
fn css(s: Str) -> json.Valuejs
fn js(s: Str) -> json.Valuejsstr
fn jsstr(s: Str) -> json.Valueurl
fn url(s: Str) -> json.Valueattr
fn attr(s: Str) -> json.Valuesrcset
fn srcset(s: Str) -> json.Value