duckweb_tpl
scalar · LOAD duckweb
duckweb_tpl(VARCHAR, ANY) -> VARCHARFills {{name}} placeholders in a template from a struct.
duckweb_tpl(
(SELECT t.body FROM templates t WHERE t.name = 'item'),
{id: m.id, note: duckweb_query(route, 'note'),
mark: '<svg width="8" height="8"></svg>'})Each field of the struct is a placeholder name. {{name}} interpolates the value HTML-escaped; {{raw:name}} inserts it verbatim.
Escaping is the default so that forgetting the marker produces a visibly over-escaped page rather than an injection — the failure you can see, not the one you ship.
When something is off
The helper never errors. It degrades in ways you can spot on the page:
- An unknown name interpolates to nothing.
- A
{{with no closing}}is left as written. - A second argument that is not a struct interpolates nothing at all, so a malformed call renders a visibly empty page rather than failing the request.
Whitespace inside the braces is trimmed, so {{ id }} and {{id}} are the same placeholder, as are {{raw: mark}} and {{raw:mark}}.