Reference · reference
template module
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
render
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.
use template
use value
let out = render "listen {{ port }};\n{% for h in hosts %}server {{ h }};\n{% endfor %}",
Map "port": Int,
"hosts": List
}),
)?