Types
struct Pair#
Key/value pair for std.template rendering.
key: string | Placeholder name, written |
|---|---|
value: string | Text substituted for it. |
Functions
Replaces every {{key}} with its pair's value; unknown placeholders stay.
template: Text carrying{{key}}placeholders.pairs: Substitutions to apply; placeholders with no pair are left as written.
let text = std.template.render(
"Hello {{name}}, welcome to {{place}}!",
[std.template.pair("name", "Ada"), std.template.pair("place", "moon")],
)
println(text) // Hello Ada, welcome to moon!
println(std.template.render("Hi {{who}}", [])) // Hi {{who}}render, line-oriented alias (identical substitution semantics).
template: Text carrying{{key}}placeholders.pairs: Substitutions to apply.
render(template, pairs) when condition holds, else the empty string.
template: Text carrying{{key}}placeholders.condition: When false, nothing is rendered at all.pairs: Substitutions to apply.
let pairs = [std.template.pair("n", "3")]
println(std.template.render_if("[{{n}} new]", true, pairs)) // [3 new]
println(std.template.render_if("[{{n}} new]", false, pairs) == "") // truefn render_each(template: string, placeholder: string, values: [string]) -> string#
Concatenates one rendering of template per value, substituting {{placeholder}} each time.
template: Text rendered once per value.placeholder: Placeholder name each value is substituted for.values: Values to render, in order.
let list = std.template.render_each("<li>{{item}}</li>", "item", ["A", "B"])
println(list) // <li>A</li><li>B</li>