Import std.text.template
Template
class
Public Class Template
A template, read once, which Render fills from what it's given each time.
Examples
Local greeting = Try Template(r"Hello, {{name}}! {{#each items}}[{{this}}]{{/each}}")
Local data = Value.Object()
data["name"] = Value("Ada")
data["items"] = Value([Value("a"), Value("b")])
Expect((Try greeting.Render(data)) == "Hello, Ada! [a][b]")-
The template that
textis, which escapes its values for HTML withhtml. Throws a FormatError of BAD_TEMPLATE where thetextisn't one, which says the line and column. -
The template, filled from a Value, whose Object's keys are the names the tags give. Throws a FormatError of MISSING_VALUE at a partial, which only Templates have.
-
The template, filled from the Value that Save makes of
data: a Struct's or Class's Fields by name, a Map's keys, and the rest as Save has them. Panics, as Save does, fordatathat nests more than 256 levels deep.Examples
Struct Page Field Title: String End Struct Local page = Try Template(r"<h1>{{Title}}</h1>", True) Expect((Try page.Render(Page("Fish & chips"))) == "<h1>Fish & chips</h1>")
Report an issue with this page or with FutureBlitz on GitHub.