Skip to content

Latest commit

 

History

History
56 lines (39 loc) · 2.26 KB

jte.md

File metadata and controls

56 lines (39 loc) · 2.26 KB

Required dependencies: io.ktor:%artifact_name%

Ktor allows you to use JTE templates as views within your application by installing the %plugin_name% plugin.

Add dependencies {id="add_dependencies"}

To handle .kte files, you need to add the gg.jte:jte-kotlin artifact to your project.

Install %plugin_name% {id="install_plugin"}

Inside the install block, you can configure how to load JTE templates.

Configure %plugin_name% {id="configure"}

Configure template loading {id="template_loading"}

To load JTE templates, you need to:

  1. Create a CodeResolver used to resolve template code. For example, you can configure DirectoryCodeResolver to load templates from a given directory or ResourceCodeResolver to load templates from application resources.
  2. Use the templateEngine property to specify a template engine, which uses a created CodeResolver 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" include-lines="3-6,9-10,13-17,24"}

Send a template in response {id="use_template"}

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" include-lines="19-22"}