Handlebars.js Templates
Last updated
Last updated
Support for templates is contained in kvision-handlebars module and is based on webpack's . Templates are automatically transformed to JavaScript functions during the build process of the application.
You put your template files (with *.hbs
extension) into src/jsMain/resources/modules/hbs
directory of your application. Then in your code you can use @JsModule
and reference your *.hbs
files. All components which render textual content (io.kvision.html.Tag
class and subclasses) have template
and templates
properties. The second one allows you to define different templates for other supported languages (see. ).
To actually call the template function and render its output in your app, you need to set some data. You can use templateData
property and use plain JavaScript object. To generate one from your data you can use obj
function builder.
You can also use toObj
extension function if you store your data in a class (or classes) with @Serializable
annotation.
The setData
extension function is a convenient shortcut for the above.