SIMPLE_TEMPLATE_QUICK

Zero-Configuration Templates for Beginners

v1.0.0 MIT

Overview

SIMPLE_TEMPLATE_QUICK provides one-liner template rendering with Mustache-style {{variable}} syntax. Auto HTML escaping for XSS protection.

For sections, partials, and advanced features, use SIMPLE_TEMPLATE directly.

Quick Start

local
    tpl: SIMPLE_TEMPLATE_QUICK
    html: STRING
do
    create tpl.make

    -- One-liner render with variables
    html := tpl.render ("Hello {{name}}!", <<["name", "World"]>>)

    -- Render from file
    html := tpl.file ("templates/email.html", <<["user", "Alice"], ["link", url]>>)

    -- Conditional rendering
    html := tpl.render_if (is_logged_in, "Welcome back!", <<>>)
    html := tpl.render_choice (has_items, cart_template, empty_template, vars)

    -- List rendering (render template for each item)
    html := tpl.render_list ("<li>{{name}}</li>", <<item1_vars, item2_vars, item3_vars>>)

    -- Simple substitution (no Mustache, just replace)
    msg := tpl.substitute ("Hello $name!", <<["$name", "Alice"]>>)

    -- Write output to file
    tpl.render_to_file (template, vars, "output.html")

    -- Get required variables from template
    across tpl.variables_in ("{{a}} and {{b}}") as v loop
        print (v)  -- "a", "b"
    end
end

API Reference

Rendering

FeatureDescription
render (template, vars)Render template with variables
file (path, vars)Render template file
render_to_file (tpl, vars, path)Render and write to file

Conditional Rendering

FeatureDescription
render_if (cond, template, vars)Render only if condition true
render_choice (cond, true_tpl, false_tpl, vars)Render based on condition

List Rendering

FeatureDescription
render_list (template, items)Render template for each item

Utilities

FeatureDescription
substitute (text, pairs)Simple string replacement
variables_in (template)Extract required variable names

Template Syntax

SyntaxDescription
{{variable}}Output variable (HTML escaped)
{{{variable}}}Output variable (raw, no escaping)
{{! comment }}Comment (not rendered)