Reputation: 629
I have a variable in my Thymeleaf context, called r. r has a getUrl that returns an URL, something like www.a.co I want to create an HTML anchor http://www.a.co Is there any better way of doing it in Thymeleaf ? My solution is the following, but I don't really like it.
<a th:href="@{http://{path}(path=${r.url})}">
<span th:text="${r.url}"/>
</a>
Upvotes: 1
Views: 1298
Reputation: 20477
There are a lot of different ways of doing this (depending on your needs). I guess I would prefer:
<a th:href="|http://${r.url}|" th:text="${r.url}" />
You might also be interested in one of these:
<a th:href="${'http://' + r.url}" th:text="${r.url}" />
<a th:href="'http://' + ${r.url}" th:text="${r.url}" />
<a th:href="@{${'http://' + r.url}}" th:text="${r.url}" />
Upvotes: 5