Skip to content
FutureBlitz

    Install

    Import std.text.template

    Template

    std.text.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]")

    std/text/template.fb, line 30

    • Public New(text: String, html: Bool = False) Throws FormatError constructor #

      The template that text is, which escapes its values for HTML with html. Throws a FormatError of BAD_TEMPLATE where the text isn't one, which says the line and column.

    • Public Method Render(data: Value): String Throws FormatError method #

      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.

    • @PanicsAtCaller Public Method Render<T>(data: T): String Throws FormatError method #

      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, for data that 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 &amp; chips</h1>")

    Report an issue with this page or with FutureBlitz on GitHub.