Question about using the Thymeleaf integration. `...
# http4k
p
Question about using the Thymeleaf integration.
Copy code
I have the following HttpHandler:
private val renderer = ThymeleafTemplates().HotReload("src/main/resources/templates")

fun getUiUserHandler(userInputPort: UserInputPort): HttpHandler =
    {
        val result = userInputPort.getAllUsers()
        result.fold(
            ifLeft = { handleFailure(it) },
            ifRight = { userList ->
                renderer.renderToResponse(UserViewModel(
                    users = userList.map {
                        UserDto(
                            id = it.id,
                            username = it.username,
                        )
                    }
                )
                )
            },
        )
    }
The
UserViewModel
looks like below:
Copy code
data class UserViewModel(
    val users: List<UserDto>,
): ViewModel{

    override fun template(): String {
        return "UserViewModel.html"
    }
}
The html file is using a basic table to show the list of users:
Copy code
<table class="table table-striped">
            <thead>
            <tr>
                <th>ID</th>
                <th>Username</th>
            </tr>
            </thead>
            <tbody>
            <tr th:each="user : ${users}">
                <td th:text="${user.id}"></td>
                <td th:text="${user.username}"></td>
            </tr>
            </tbody>
        </table>
Everything works fine, but there are no entries shown in the table. Do I miss something in the configuration? I could not find more information in the documentation besides https://www.http4k.org/ecosystem/http4k/reference/templating/
1
d
in thymeleaf everything needs to be prepended as
model.<field>
because effectively we need to pass a map intot he template
p
Thanks. That solves the problem 👍