Required dependencies: io.ktor:%artifact_name%
Ktor allows you to use JTE templates as views within your application by installing the %plugin_name% plugin.
To handle
.kte
files, you need to add thegg.jte:jte-kotlin
artifact to your project.
Inside the install
block, you can configure how to load JTE templates.
To load JTE templates, you need to:
- Create a
CodeResolver
used to resolve template code. For example, you can configureDirectoryCodeResolver
to load templates from a given directory orResourceCodeResolver
to load templates from application resources. - Use the
templateEngine
property to specify a template engine, which uses a createdCodeResolver
to transfer templates into native Java/Kotlin code.
For instance, the code snippet below enables Ktor to look up JTE templates in the templates
directory:
{src="snippets/jte/src/main/kotlin/com/example/Application.kt" lines="14-17"}
Suppose you have the index.kte
template in the templates
directory:
{src="snippets/jte/templates/index.kte"}
To use the template for the specified route, pass JteContent
to the call.respond
method in the following way:
{src="snippets/jte/src/main/kotlin/com/example/Application.kt" lines="19-22"}