Reference · reference

template module

1 min read · 2026-09-02 · config-weave 0.1.0

use template renders Tera templates against a map of variables. It backs the linux_files.template resource. Autoescaping is off, because the output is a configuration file rather than HTML. The one function returns Result[string, string] and fails on a template syntax error or a missing variable.

render

rust
template::render(template: string, vars: Value) -> Result[string, string]

Renders template with the entries of vars as its variables. vars must be a Value::Map; Value::Null renders with an empty context, and any other kind of value is an error. The template language provides {{ x }} expressions, {% for %} and {% if %} blocks, and Tera's filters.

Author template bodies as raw heredocs

Write a template body in WCL as a raw heredoc, <<'TMPL', so WCL's own ${} interpolation leaves Tera's {{ }} and {% %} markers alone. Pass data through vars.

rust
use template
use value

let out = template::render(
    "listen {{ port }};\n{% for h in hosts %}server {{ h }};\n{% endfor %}",
    Value::Map(#{
        "port": Value::Int(8080),
        "hosts": Value::List([Value::String("a"), Value::String("b")])
    }),
)?