Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
old
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Korte

Korte

Template Engine for Multiplatform Kotlin

Build Status Maven Central Discord

Full Documentation: https://korlibs.soywiz.com/korte/

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

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()
     }
 }