Skip to content

template://

Producer-only Go template renderer. Uses stdlib html/template (auto-escaping) or text/template (no escaping), augmented with the Masterminds/sprig/v3 helper set (~100 helpers across strings, math, dates, dicts, lists, regex, semver, crypto). The exchange body is the data context (map[string]any or JSON-decoded equivalent).

Use template:// to compose HTML reports, email bodies, prompts, configuration files — anything where a parameterized text artifact comes out of structured input.

Producer-only — CreateConsumer returns ErrConsumerNotSupported.

URI shape

template://<name>?path=templates/report.html&engine=html&sprig=true&missingKey=zero

Parameters

Param Type Default Description
path string — Single template file. Mutually exclusive with glob / inline.
glob string — Glob pattern. First match is the entry template; the rest are available as named blocks ({{ template "name" . }}).
inline string — Inline template source (URL-encoded).
engine enum html html (auto-escapes per context) or text (raw).
sprig boolean true Install the sprig/v3 helper FuncMap.
missingKey enum zero Behavior on missing key: default/invalid → <no value>, zero → zero value, error → abort.
name string derived Override the named entry template to execute.
contentType string text/html Content-Type set on the output.
trimSpace boolean false Trim leading/trailing whitespace from output.
leftDelim string {{ Override left action delimiter.
rightDelim string }} Override right action delimiter.

Source resolution

  1. URI param path=...
  2. URI param glob=...
  3. URI param inline=...
  4. Exchange header template.source (template string)
  5. Exchange header template.path (file path)

Compiled templates are cached per (kind, source) tuple on the endpoint, so file reads only happen on first use (and a cache miss on a different source kind).

Headers

Header Direction Description
template.source Read Inline template per exchange.
template.path Read Template file path per exchange.
template.engine Written html or text.
template.bytes Written Output length.
Content-Type Written From the contentType param.

The output body is a string. The component overwrites both Out() and In() so the next pipeline step sees the rendered text rather than the data context.

Body coercion

The body is "dot-into-able" Go data. JSON-encoded strings / byte slices are auto-parsed (so a Starlang output application/json step upstream "just works"). Maps and slices pass through. Other types pass through and dot-expressions get evaluated against them.

Examples

Inline HTML template, sprig-enabled:

- set-body:
    starlang: '{ "user": payload.name, "tags": ["a","b","c"] }'
- target: |
    template://greet?engine=html&inline=
    %3Ch1%3EHello%20%7B%7B%20.user%20%7C%20title%20%7D%7D%21%3C%2Fh1%3E
    %3Cul%3E%7B%7B%20range%20.tags%20%7D%7D%3Cli%3E%7B%7B%20.%20%7D%7D%3C%2Fli%3E%7B%7B%20end%20%7D%7D%3C%2Ful%3E

File-backed template with named subtemplates:

templates/report.html
templates/_header.html
templates/_footer.html
- target: template://report?glob=templates/*.html&name=report.html

Pick a template at runtime:

- set-header:
    name: template.path
    starlang: '"templates/" ++ payload.type ++ ".html"'
- target: template://dispatch?engine=html

Text template (no escaping) — handy for prompt construction:

- target: template://prompt?engine=text&contentType=text/plain&path=prompts/research.txt&missingKey=error

Behavior notes

  • Caching — first call per (kind, source) parses; subsequent calls reuse. Changing the file on disk requires restarting the endpoint (no auto-reload).
  • missingKey defaults to zero — strictest sensible value for downstream parsers (no stray <no value> text). Set missingKey=error to fail-fast when a key is missing.
  • SetRootDir(...) — when called programmatically, restricts path= / glob= lookups to a directory; paths escaping the root via .. are rejected. The default component (no root) accepts any readable file path the process can open.
  • sprig — by default installed; disable with sprig=false for strict, no-extras rendering.
  • HTML auto-escape — context-aware per html/template's rules ({{ . }} inside <a href=""> URL-escapes, inside an HTML element body it HTML-escapes, etc.). Use engine=text to bypass this when generating non-HTML output (CSV, plain text, prompts, code).

Source

pkg/component/template/template.go

See also

  • pdf — render a template to HTML, PDF it.
  • chart — embed chart data URIs into templates.
  • Starlang guide — the default expression engine; complementary to Go templates.