Skip to content

Latest commit

 

History

History
60 lines (40 loc) · 2.22 KB

pebble.md

File metadata and controls

60 lines (40 loc) · 2.22 KB

Required dependencies: io.ktor:%artifact_name%

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

Add dependencies {id="add_dependencies"}

Install Pebble {id="install_plugin"}

Inside the install block, you can configure the PebbleEngine.Builder for loading Pebble templates.

Configure Pebble {id="configure"}

Configure template loading {id="template_loading"}

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"}

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

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"}