Skip to content
FutureBlitz

    Install

    Import std.text.template

    std.text.template

    std.text.template: Mustache-style templates, which a Value fills, or a Struct, a Class, or a Map, through the Value that Save makes of it. A template is text with tags in "{{ }}", each filled in when it's rendered: {{name}} gives a value, the blocks {{#each name}}, {{#if name}}, and {{#unless name}} go over or test one, with an {{else}} for when there's nothing, {{> name}} renders another template there, and {{! }} is a comment. A value can take a format spec, as {{price:.2}} does, as interpolation's "{price:.2}" would. A block's tag alone on its line takes the line with it. A template for HTML escapes its values.

    std/text/template.fb

    Types

    Template class

    Public Class Template

    A template, read once, which Render fills from what it's given each time.

    std/text/template.fb, line 18

    • 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.

    Templates 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.

    std/text/template.fb, line 45

    • 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.