template
lib/template.vklib/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.
render-html = fn [tpl str, ctx map] str
Renders tpl against ctx with automatic HTML escaping on {{ expr }} ({{{ raw }}} opts out).
Executable Example
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><Ada></h1><ul><li>oro</li><li>pqc</li></ul>' [ err 'template html' ] else [ .ok ]
render-text = fn [tpl str, ctx map] str
Renders tpl against ctx as plain text (no HTML escaping).