Skip to main content

//clika-runtime/io.clika.runtime/Template

Template

[common]
class Template

A parsed, reusable text template (the engine the chat templates use): parse once, render against a JSON object of variables as often as needed. Malformed syntax fails at parse; an undefined variable in a strict position or a type error fails at render. AutoCloseable.

Template.parse("Hello {{ name }}!").use { greeting ->
Json.newObject().set("name", "World").use { context -> greeting.render(context) } // Hello World!
}

Types​

NameSummary
Companion[common]
object Companion

Functions​

NameSummary
close[common]
open fun close()
render[common]
fun render(context: Json): String
Render against context, a JSON object whose members are the template's variables.