5

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"/>
0

2 Answers 2

10

Try Server-relative URLs:

<img class="info" th:src="@{~/resources/img/image.png}" />

UPD
Actual link to url part of Thymeleaf 2.1. tutorial

Sign up to request clarification or add additional context in comments.

Comments

0

You can pass the baseUrl as parameter to template. Then: <a th:href="${baseUrl + '/my/uri?maybe=' + someParam}". Hope that helps.

1 Comment

Merci Toshko! I needed to embed a baseUrl since I'm using Thymeleaf to process email templates.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.