B
B
Biaci_Anj2022-01-26 03:07:30
Java
Biaci_Anj, 2022-01-26 03:07:30

Thymeleaf, th:text doesn't work when inside another th:text, how to get around?

Here is a simple example of how to get around this, I'm considering any options, I would be very grateful for the help.

Here price is simply not shown, everything is eaten by name

<h4 th:text="${product.name}">Some product<span th:text="${product.getPrice()}">45</span></h4>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Orkhan, 2022-01-26
@Biaci_Anj

If memory serves, then you need something like th:inline
this:

<h4 th:inline="text"><span th:text="${product.getPrice()}">45</span></h4>

Here, read this question:
https://stackoverflow.com/questions/25071985/thyme...

M
Michael, 2022-01-26
@Akela_wolf

Probably so? Otherwise, substituting content in the h4 tag will overwrite the template that you wrote in it.

<h4><span th:text="${product.name}">Some product</span><span th:text="${product.getPrice()}">45</span></h4>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question