Skip to content

Templates

Register Template Adapters

Example to show how to register template adapters. full test.

Using regular Expressions

1
2
3
4
5
TemplateManager.adapters = mapOf(
    Regex(".*\\.html") to SampleTemplateAdapter("html"),
    Regex(".*\\.txt") to SampleTemplateAdapter("text"),
    Regex(".*") to SampleTemplateAdapter("others"),
)

Using globs

1
2
3
4
5
TemplateManager.adapters = mapOf(
    Glob("*.html").regex to SampleTemplateAdapter("html"),
    Glob("*.txt").regex to SampleTemplateAdapter("text"),
    Glob("*").regex to SampleTemplateAdapter("others"),
)

Process Templates

Simple example to show how to process templates. full test.

1
2
val context = mapOf("key1" to "value1", "key2" to "value2")
val rendered = TemplateManager.render(urlOf("classpath:template.txt"), context)