Is there a way of referencing a model attribute in a th:href link? For example
<a th:text="${currentUser}" th:href="@{/user/{currentUser}}"></a>
Here, currentUser is a model variable as specified in a controller. This can be accessed easily as seen in the th:text tag. However, the th:href fails the thymeleaf parsing. If there any way of referencing a model attribute in this way, in the th:href? For reference, this is a Spring MVC (bootstrap) application with Thymeleaf support.
In order to include a model variable in th:href
you have to include it with the ${...}
indicator, you could use the pipes to easily concatenate:
<a th:text="${currentUser}" th:href="@{|/user/${currentUser}|}"></a>
Official documentation on url syntax here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With