Required dependencies: io.ktor:%artifact_name%
Ktor allows you to use Pebble templates as views within your application by installing the Pebble plugin.
Inside the install
block, you can configure the PebbleEngine.Builder for loading Pebble templates.
To load templates, you need to configure how to load templates using PebbleEngine.Builder. For example, the code snippet below enables Ktor to look up templates in the templates
package relative to the current classpath:
{src="snippets/pebble/src/main/kotlin/com/example/Application.kt" include-lines="3-5,10-16,23"}
Imagine you have the index.html
template in resources/templates
:
{src="snippets/pebble/src/main/resources/templates/index.html"}
A data model for a user looks as follows:
{src="snippets/pebble/src/main/kotlin/com/example/Application.kt" include-lines="25"}
To use the template for the specified route, pass PebbleContent
to the call.respond
method in the following way:
{src="snippets/pebble/src/main/kotlin/com/example/Application.kt" include-lines="18-21"}