Thymeleaf
To enable support, you need to include the ktor-thymeleaf
artifact in the build script:
Gradle (Groovy)
Maven
To install the Thymeleaf
feature, pass it to the install
function in the application initialization code. This can be the main
function …
import io.ktor.features.*
fun Application.main() {
install(Thymeleaf)
}
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:
import io.ktor.thymeleaf.*
prefix = "templates/"
suffix = ".html"
characterEncoding = "utf-8"
})
}
Send a Template in Response
Imagine you have the index.html
template in resources/templates
:
A data model for a user looks as follows: