Gerard de Leeuw
08/07/2021, 1:09 PMHtmlContent {
head { title { +"Posts" } }
}
Here you are effectively calling the constructor of HtmlContent and adding content to it, but you are not returning the constructed instance. Your function respondWithPostList
has no return type, so it will implicitly return Unit
.
I think the most neat solution is to make your respondWithPostList
function an extension method of HtmlContent
. So it would look like this:
fun HtmlContent.respondWithPostList(posts: List<PostDTO>?) {
head { title { +"Posts" } }
body {
posts?.forEach { post ->
run {
div {
h3 {+"${post.title} (${post.id})"}
p {+post.author.email}
}
}
}
}
}
Hadi
08/07/2021, 4:37 PMGerard de Leeuw
08/07/2021, 5:59 PMGerard de Leeuw
08/07/2021, 5:59 PMHadi
08/07/2021, 6:16 PM