Release 4.6 - Kotlin Extensions with Function Literals with Receiver
· One min read
All HTML builders are now available through Kotlin Extensions with function literals with receiver, enabling both nested method and method chaining idioms.
You can write HTML structures in a natural, hierarchical way using nested lambdas, or use method chaining for concise simple sequences:
- Nested Method
- Method Chaining
Nested Method Example
body {
div {
p {
text("Hello")
}
}
}
Method Chaining Example
body.div.p.text("Hello").l.l.l
note
The l builder emits the end tag, allowing fluent construction of HTML elements.
Both approaches are available depending on your preference - nested lambdas for readability with complex structures, or method chaining for concise simple sequences.