Velocity
Ktor allows you to use Velocity templates as views within your application by installing the Velocity plugin (previously known as feature).
Add dependencies
To enable Velocity support, you need to include the ktor-velocity artifact in the build script:
Install Velocity
To install the Velocity plugin, pass it to the install function in the application initialization code. Depending on the way used to create a server, this can be the embeddedServer function call ...
... or a specified module.
Configure Velocity
Configure template loading
Inside the install block, you can configure the VelocityEngine. For example, if you want to use templates from the classpath, use a resource loader for classpath:
Send a template in response
Imagine you have the index.vl template in resources/templates:
A data model for a user looks as follows:
To use the template for the specified route, pass VelocityContent to the call.respond method in the following way: