Handlebars.js templates
Support for Handlebars.js templates is contained in kvision-handlebars module and is based on webpack's handlebars loader. Templates are automatically transformed to JavaScript functions during the build process of the application.
You put your template files (with *.hbs
extension) into src/main/resources/hbs
directory of your application. Then in your code you can just require
your *.hbs
files. All components which render textual content (pl.treksoft.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. Internationalization).
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.
Last updated