Does anyone have any experience of using http4k, T...
# http4k
d
Does anyone have any experience of using http4k, Thymeleaf and htmx to render partials (I’m thinking the contents of a table when it updates) from a whole page template? @Mikael Ståldal I see you have been using fragments
m
No, I only got this far with Thymeleaf: https://github.com/mikaelstaldal/htmx-http4k-thymeleaf Seems like the current http4k integration with Thymeleaf does not support partials.
And now I have switched to Kotlin DSL instead, which seems nicer for this purpose: https://github.com/mikaelstaldal/htmx-http4k-dsl
d
Thanks. I like the DSL, but find it hard work for prototyping whole pages. I’ll play with Thymeleaf some more, or maybe pre- or post-process some Handlebars
m
Yes, the Natural Templates feature of Thymeleaf can be useful.
a
Looks like you already posted your video but in the future I would strongly suggest jte as opposed to Thymeleaf for any server-side templating, and especially for producing HTMX partials. jte allows you to write templates in pure Kotlin, and to use native Kotlin objects/classes in those templates, so you can simply pass in the objects you are already working with. This is, by far, the most productive web stack I've ever used. Super impressed by this project and its developer.
🙏 1
d
I have posted a video, but that one is using Handlebars - I haven’t got around to Thymeleaf yet, so thanks for the tip, I’ll check it out
m
JTE looks very much like JSP (24 years old technology, which has mostly gone out of fashion). In what way is it better than kotlinx.html if you use Kotlin?
d
I must say that was the vibe I got reading the docs!
a
Server-rendered web sites/apps as a whole went out of fashion, originally due to jQuery/Backbone/Knockout and then by Angular, React, Vue, etc, and pre-rendered static sites. Those are all still fine, if that's how you want to build something. HTMX has re-introduced an older paradigm, where the server is sending back fully-formed HTML rather than bare JSON data. If you buy into that concept then you probably need a templating engine on the server, and JTE is by far the best/easiest one I've seen when the rest of the backend is written in Kotlin, due to how well it integrates and ability to naturally use native objects/classes, just like any other part of your code.
m
So how is it better than kotlinx.html?
a
I'm familiar with the library but not sure what problem it is solving. I'd just rather write HTML itself than a custom derivative of it. JTE templates support hot-reloading and can also be auto-crawled in real-time by tailwind's CLI (for tree-shaking). I don't know if kotlinx does either of those (kudos if it does)
m
kotlinx.html solves the problem of server-side HTML rendering.
(And to be fair, JTE is also a custom derivative of HTML, not HTML itself.)
a
The forum we're in, http4k, supports 8 different templating alternatives, so it would appear kotlinx isn't a solution that works for everyone. I prefer JTE to the others, that's just me.
m
BTW, given that is is apparently similar to JSP, what are the advantages of JTE over JSP?
a
Never looked at JSP before 20 minutes ago so I'm not qualified to answer
m
Oh, so you never did server-rendered web-apps in Java before it went out of fashion? 😉
a
Not in Java. I messed around with ASP (before it was ASP.NET) and with ColdFusion and XSLT... and then was out of software entirely for about 15 years, when I came back it was all about Python and RoR. Probably would have left again if it wasn't for Kotlin.