Reputation: 3536
I use Thymeleaf for the templates of a web application.
When I make a link I use a URL like this:
<img class="info"
src="../../../resources/img/image.png"
th:src="@{/resources/img/image.png}" />
How can I configure the base URL in Thymeleaf?
I need this because my application runs in the current URL:
http://localhost:8080/myapp
And it works fine, but then it redirects to:
http://www.myapp.com/
Then the images was search in:
http://www.myapp.com/myapp/resources/img/image.png
instead of:
http://www.myapp.com/resources/img/image.png
I want something like:
<property name="baseURL" value="http://www.myapp.com"/>
Upvotes: 5
Views: 22659
Reputation: 2541
You can pass the baseUrl as parameter to template. Then: <a th:href="${baseUrl + '/my/uri?maybe=' + someParam}"
. Hope that helps.
Upvotes: 0
Reputation: 2167
Try Server-relative URLs:
<img class="info" th:src="@{~/resources/img/image.png}" />
UPD
Actual link to url part of Thymeleaf 2.1. tutorial
Upvotes: 10