veko doc
Self-Contained API Reference • Gradual Types • Capabilities • Wasm Sandbox

template

lib/template.vk

lib/template.vk Pure-Veko safe HTML-escaping and plain-text template engine. Supports {{ var }} (auto-escaped in HTML mode), {{{ raw }}} (unescaped), dotted path lookup (user.name, . inside loops), {{#if cond}}...{{else}}...{{/if}}, and {{#each list}}...{{/each}}. Zero capabilities required.

signature
escape-html = fn [s str] str

Escapes HTML entities (&, <, >, ", ').

signature
render-html = fn [tpl str, ctx map] str

Renders tpl against ctx with automatic HTML escaping on {{ expr }} ({{{ raw }}} opts out).

Executable Example
veko
use [tpl = template]
out = tpl/render-html '<h1>{{ user.name }}</h1>{{#if admin}}<ul>{{#each tags}}<li>{{ . }}</li>{{/each}}</ul>{{/if}}' { user = { name = '<Ada>' }, admin = true, tags = ['oro' 'pqc'] }
if out != '<h1>&lt;Ada&gt;</h1><ul><li>oro</li><li>pqc</li></ul>' [ err 'template html' ] else [ .ok ]
signature
render-text = fn [tpl str, ctx map] str

Renders tpl against ctx as plain text (no HTML escaping).