TemplateProcessor

Utility object for injecting dynamic values into templates.

For example, given the following template and input context

Template:

Hello, {{user.name}}. Context:

{
"user": {
"name": "Bill"
}
}

The processed template would output

Hello, Bill.

In cases where the value may not be available in the context, a fallback string can be provided to be used instead. So given the following template and input context:

Template:

Hello, {{user.name || beloved user}}. Context:

{
"user": {
"age": 42
}
}

The processed template would output

Hello, beloved user.

Types

Link copied to clipboard
interface Template

A reusable, pre-processed version of some templated text. Any substitutions are discovered ahead of time and can be inspected in substitutions.

Functions

Link copied to clipboard

Compiles a reusable, partially processed Template from the given template text. Any substitutions are discovered ahead of time and can be inspected in Template.substitutions.

Link copied to clipboard
fun process(template: String, context: DataObject): String

Processes the input template looking for all occurrences of double brace wrapped text: {{ }}