Skip to content
FutureBlitz

    Install

    Import std.text.template

    Templates

    std.text.template

    class

    Public Class Templates

    Templates by name, which render each other as partials: {{> header}} is the template named "header". One whose name ends with ".html" or ".htm" escapes its values for HTML, as a partial too, and so do the partials it renders, whatever their names.

    Examples

    Local site = Templates()
    Try site.Add("header", r"<h1>{{title}}</h1>")
    Try site.Add("page", r"{{> header}}<p>{{body}}</p>")
    Local data = Value.Object()
    data["title"] = Value("Hi")
    data["body"] = Value("there")
    Expect((Try site.Render("page", data)) == "<h1>Hi</h1><p>there</p>")

    std/text/template.fb, line 80

    • Public New() constructor #

      A new Templates, with none added.

    • Public Method Add(name: String, text: String) Throws FormatError method #

      Adds the template that text is as name, in place of one that has the name already. Throws a FormatError of BAD_TEMPLATE where the text isn't one, which says the template's name, the line, and the column.

    • Public Method Contains(name: String): Bool method #

      Whether it has a template of the name.

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

      The template of the name, filled from a Value, whose Object's keys are the names the tags give. Throws a FormatError of MISSING_VALUE where it has no template of the name, or of a partial's, and of OTHER for partials more than 1000 deep inside each other.

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

      The template of the name, filled from the Value that Save makes of data. Panics, as Save does, for data that nests more than 256 levels deep.

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