Ktor includes support for Velocity templates through the Velocity feature. Initialize the Velocity feature with the VelocityEngine:
io.ktor:ktor-velocity:$ktor_version
中的
io.ktor.velocity.Velocity
类中定义。
dependencies {
implementation "io.ktor:ktor-velocity:$ktor_version"
}
dependencies {
implementation("io.ktor:ktor-velocity:$ktor_version")
}
<project>
...
<dependencies>
<dependency>
<groupId>io.ktor</groupId>
<artifactId>ktor-velocity</artifactId>
<version>${ktor.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
You can install Velocity, and configure the VelocityEngine
.
install(Velocity) {
setProperty("resource.loader", "classpath")
setProperty("classpath.resource.loader.class", ClasspathResourceLoader::class.java.name)
}
}
When Velocity is configured, you can call the call.respond
method with a VelocityContent
instance:
data class User(val name: String, val email: String)
get("/") {
val user = User("user name", "[email protected]")
call.respond(VelocityContent("templates/hello.vl", user))
}