Questions tagged [kotlinx-html]

A kotlinx.html library provides DSL to build HTML

kotlinx.html is a library for building HTML pages for the Kotlin language. You can use it on both server and client side. Also it provides way to build HTML pages to a stream and to a DOM tree.

See wiki for more info.

19 questions
4
votes
0 answers

How to await inside a crossinline lambda from a suspend function?

I am using KotlinX.html to emit HTML to an output stream (e.g. FileWriter in the next sample) and the resulting HTML view depends of asynchronous data from a CompletableFuture (e.g. cfArtist). I want to immediately start emitting static HTML (i.e.…
Miguel Gamboa
  • 8,855
  • 7
  • 47
  • 94
4
votes
2 answers

When using kotlinx.html's DSL to create HTML, (how) is it possible to refer to the created elements?

I'm writing a browser app in Kotlin/JS, and I'm using kotlinx.html's DSL to generate some of the HTML. For (a simple) example: (window.document.body!! as Node).append { p { +"Some text" } p { +"Click here" …
Tom
  • 4,910
  • 5
  • 33
  • 48
4
votes
3 answers

How do I create the onClick function for a button with Kotlinx.html?

I am using Kotlin's html library kotlinx.html for dynamic html building. I want to create a button which triggers a function when clicked. This is my current code: class TempStackOverflow(): Template { var counter: Int = 1 …
Lekkkim
  • 43
  • 3
3
votes
2 answers

How do I provide a page template in kotlinx-html?

I would like to generate a bunch of HTML files with kotlinx-html and I want to start each file with the same template. I would like to have a function for the base structure and provide a lamda to this function for the specific content like so (non…
ChrLipp
  • 15,526
  • 10
  • 75
  • 107
3
votes
1 answer

Compose HTML with kotlinx.html

I'm trying to build html layout page usin kotlinx.html. I can create main page, but having problem breaking it to parts generated by separate functions. I don't know how to include html created in separate function into main document. I had success…
Pavel Niedoba
  • 1,554
  • 2
  • 19
  • 36
3
votes
1 answer

How to use the Kotlinx.html in Spring in place of the normal html template engine for JSP or Thymeleaf?

The flaw of the traditional html template engine is the absence of type-safe and compile-time checking. Some gurus suggested that Kotlinx.html might greatly compensate the flaw of traditional html template engine. So I plan to make use of Spring in…
Rui
  • 3,454
  • 6
  • 37
  • 70
3
votes
2 answers

Create CSS class with kotlinx.html DSL

I'm using Kotlin to Javascript plugin and kotlinx.html library to build sample app: fun main(args: Array) { window.onload = { document.body!!.append.div { a("#", classes = "red") { +"Link" …
Kirill
  • 7,580
  • 6
  • 44
  • 95
3
votes
2 answers

Could not find org.jetbrains.kotlinx:kotlinx-html:0.6.4

I'm trying to test the HTML Application, my build.gradle dependencies are: dependencies { compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version" compile "org.jetbrains.ktor:ktor-core:$ktor_version" compile…
Hasan A Yousef
  • 22,789
  • 24
  • 132
  • 203
2
votes
2 answers

Styling HTML elements at Kotlin-js

How can I style my HTML elements when using Kotlinx-html, I've my app working fine, then I tried to add styling using AZA-Kotlin, but once I imported azadev.kotlin It gave me error build My full code is a s below: Main.kt: import…
Hasan A Yousef
  • 22,789
  • 24
  • 132
  • 203
2
votes
1 answer

Kotlin HTML-Builder

In Kotlin page, under HTML-Builder I can see the below code, how can I use it in simple .tk file? how t get started here? val data = mapOf(1 to "one", 2 to "two") createHTML().table { for ((num, string) in data) { Iterate over data tr…
Hasan A Yousef
  • 22,789
  • 24
  • 132
  • 203
1
vote
1 answer

Build HTML by iteration with kotlinx.html

I'm trying to build an HTML list using kotlinx.html by iterating over a collection, for each element in the collection I want to build an LI tag inside a UL tag. This is what I'm trying: fun showProducts(products: List) { …
fpiechowski
  • 517
  • 1
  • 7
  • 21
1
vote
1 answer

How to generate HTML tags from Kotlin?

I would like to generate HTML from Kotlin (running in the browser). I tried the Kotlinx library but it doesn't support callbacks, such as: div { onclick = { event -> window.alert("Kotlin!") } } Are there other similar libraries?…
dilvan
  • 2,109
  • 2
  • 20
  • 32
0
votes
0 answers

When using kotlinx.html's DSL to create HTML, (how) is it possible to refer to nested elements?

I'm using kotlinx.html's DSL to create HTML, and I need references to some of the elements created (to refer to them in event handlers etc.). However, while the functions used directly within the block passed to Node.append do return references to…
Tom
  • 4,910
  • 5
  • 33
  • 48
0
votes
1 answer

How to avoid tags from try block in output on exceptions with kotlinx.html

With kotlinx.html, exception handling looks counter-intuitive to me. In a try-catch block, tags created in the try block are still part of the HTML output even if an exception occurs. How can this be prevented. Example code: import…
languitar
  • 6,554
  • 2
  • 37
  • 62
0
votes
0 answers

how to specify background url for CSS using kotlin dsl

I want to load the background from a local file in the project using Kotlin dsl for css, and the original css file snippet looks like this: body { margin: 50; background: url("banana.png") repeat 0 0; animation: animate 15s infinite; …
1
2