Skip to main content

Module template

Module template 

Source
Expand description

Universal {{namespace.path}} template engine.

Complements $var/${var} interpolation (super::interpolate) with a syntax that is unambiguous by construction: any {{...}} that doesn’t match a known namespace path passes through as a literal (no silent-empty, no escape syntax needed). This lets the engine be applied universally — including to fields holding secrets, regexes, or $1/$ref values that the legacy $ syntax would corrupt.

Grammar: {{ \s* <namespace path> \s* }}, no nesting. Namespaces:

  • request.method|path|host|scheme|body
  • request.headers.<name> / request.query.<name> / request.cookies.<name>
  • response.status|body, response.headers.<name>
  • message.<key> (key may itself contain dots)
  • client.ip|port
  • env.<NAME> — resolved at parse time from the process environment (or an injected lookup fn), never at render time.

Anything else — an unrecognized first segment, a malformed remainder within a known namespace, or an unclosed {{ — passes through literally. A malformed remainder within a known namespace (and an unset env.*) additionally produces a warning string from Template::parse.

Template::render_with_legacy applies the legacy interpolate pass to the template’s literal segments only; rendered {{...}} output is never $-processed, so runtime data can never become a $var read primitive.

Structs§

Template
A parsed template, ready to render repeatedly against different contexts.

Enums§

Classified 🔒
Outcome of classifying one {{...}} occurrence’s trimmed inner text.
Segment
One chunk of a parsed template: either raw text or a resolvable reference.
TemplateRef
A single resolvable reference inside a template.

Functions§

classify 🔒
classify_client 🔒
classify_env 🔒
classify_message 🔒
classify_request 🔒
classify_response 🔒
named_ref 🔒
Builds a Ref classification for a <namespace>.<subkey>.<name> leaf, warning instead when name is empty (e.g. {{request.headers.}}).
render_ref 🔒
unknown_ref_warning 🔒