Skip to content

Latest commit

 

History

History
50 lines (36 loc) · 2 KB

thymeleaf.md

File metadata and controls

50 lines (36 loc) · 2 KB

Required dependencies: io.ktor:%artifact_name%

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

Add dependencies {id="add_dependencies"}

Install Thymeleaf {id="install_plugin"}

Configure Thymeleaf {id="configure"}

Configure template loading {id="template_loading"}

Inside the install block, you can configure the ClassLoaderTemplateResolver. For example, the code snippet below enables Ktor to look up *.html templates in the templates package relative to the current classpath:

{src="snippets/thymeleaf/src/main/kotlin/com/example/Application.kt" lines="12-18"}

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

Imagine you have the index.html template in resources/templates:

{src="snippets/thymeleaf/src/main/resources/templates/index.html"}

A data model for a user looks as follows:

{src="snippets/thymeleaf/src/main/kotlin/com/example/Application.kt" lines="27"}

To use the template for the specified route, pass ThymeleafContent to the call.respond method in the following way:

{src="snippets/thymeleaf/src/main/kotlin/com/example/Application.kt" lines="20-23"}