Korte
Template Engine for Multiplatform Kotlin
Support korte
If you like korte, or want your company logo here, please consider becoming a sponsor ★,
in addition to ensure the continuity of the project, you will get exclusive content.
Info:
KorTE is an asynchronous templating engine for Multiplatform Kotlin 1.3+.
It is a non-strict super set of twig / django / atpl.js template engines and can support liquid templating engine as well with frontmatter.
It has out of the box support for ktor and vert.x.
It works on JVM and JS out of the box. And on Native with untyped model data or by making the models implement the DynamicType interface.
Because asynchrony is in its name and soul, it allows to call suspending methods from within your templates.
Documentation:
Live demo
- ACE: https://korlibs.github.io/korte-samples/korte-sample-browser/web/
- OLD: https://korlibs.github.io/kor_samples/korte1/
Example
resources/views/_base.html
<html><head></head><body>
{% block content %}default content{% endblock %}
</body></html>
resources/views/_two_columns.html
{% extends "_base.html" %}
{% block content %}
<div>{% block left %}default left column{% endblock %}</div>
<div>{% block right %}default right column{% endblock %}</div>
{% endblock %}
resources/views/index.html
{% extends "_two_columns.html" %}
{% block left %}
My left column. Hello {{ name|upper }}
{% endblock %}
{% block right %}
My prefix {{ parent() }} with additional content
{% endblock %}
code.kt
val renderer = Templates(ResourceTemplateProvider("views"), cache = true)
val output = templates.render("index.html", mapOf("name" to "world"))
println(output)
class ResourceTemplateProvider(private val basePath: String) : TemplateProvider {
override suspend fun get(template: String): String? {
return this::class.java.classLoader.getResource(Paths.get(basePath, template).toString()).readText()
}
}