@std/text/template.ms#
Import each required symbol with import Name from "@std/text/template.ms".
RenderOptions Type#
Settings for Template.render and Template.render_to.
type RenderOptions {
partials Map[String, Template] = Map[String, Template]()
strict Bool = true
max_output Int? = null
max_depth Int? = 64
}RenderOptions.max_depth#
Optional maximum partial include depth; null imposes no limit.
max_depth Int? = 64RenderOptions.max_output#
Optional maximum text length in bytes; null imposes no limit.
max_output Int? = nullRenderOptions.partials#
Templates that include can name.
partials Map[String, Template] = Map[String, Template]()RenderOptions.strict#
When true, a missing printed path fails the render; when false, it prints as empty.
strict Bool = trueTemplate Type#
A compiled template; render it any number of times.
opaque type Template {
}Template.render#
Renders the template with data and the settings in options. When data is an
object, its members supply the root names.
fn render(data JsonValue, options RenderOptions = RenderOptions()) Result[String, Error]Template.render_to#
Renders this template as render does and writes the text to output. The caller
keeps output and closes it. A failed render writes nothing; a failed write returns
the stream’s error.
fn render_to(data JsonValue, var output WriteStream[String], options RenderOptions = RenderOptions()) Result[Void, Error]TemplateBranch Type#
One if or else if arm of a conditional node. Internal to the engine.
opaque type TemplateBranch {
}TemplateExpr Enum#
A parsed template expression: a literal, a path, a filter call or an operator. Internal to the engine; hidden from callers.
opaque enum TemplateExpr {
}TemplateNode Enum#
A parsed template node: text, a printed value, a conditional, a loop or an include. Internal to the engine.
opaque enum TemplateNode {
}compile Function#
Compiles template source. With html: true, printed values are HTML-escaped unless
the action ends in | raw.
fn compile(source String, html Bool = false) Result[Template, Error] { ... }render Function#
Compiles and renders in one call, with default RenderOptions. Use compile when
rendering more than once.
fn render(source String, data JsonValue, html Bool = false) Result[String, Error] { ... }to_data Function#
Converts any Data value (records, lists, scalars) to the JsonValue that a
template reads.
fn to_data[T Data](value T) Result[JsonValue, Error] { ... }