Reputation: 2377
I am trying to inject a domain url into a link using Thymeleaf. My url is being passed from the controller because i put logging and saw it.
my link is as such in my Thymeleaf html template:
<link type="text/css" th:href="@{${DomainUrl}/web/assets/css/foundation5/foundation.min.css}" rel="stylesheet" />
however, when I run it locally it doesn't replace the domain, for example, throws an error (because the URL is not found of course) render as such: http://localhost:8081/pss/ui/$%7BDomainUrl%7D/web/assets/css/components.css
Upvotes: 7
Views: 7464
Reputation: 2377
I found the solution for it. I had to make the link into literal as such:
<link type="text/css" th:href="@{|${DomainUrl}/web/assets/css/foundation5/normalize.css|}" rel="stylesheet" />
Upvotes: 2
Reputation: 32507
Ok so in order for this to work you must use preprocess operator __expression__
to get propert link so you will end up with somethink like this
<link type="text/css" th:href="@{__${DomainUrl}__/web/assets/css/foundation5/foundation.min.css}" rel="stylesheet" />
this will preprocess and resolve ${DomainUrl}
expression, and will pass resulting string to to @
expression processor. Tested and work like charm:
<a th:href="@{__${currentUrl}__/blah/blah/blahhhh}">hey there</a>
generates
<a href="http://localhost:8080/admin/place/list/blah/blah/blahhhh">hey there</a>
where http://localhost:8080/admin/place/list/
is currentUrl
in my
Upvotes: 7
Reputation: 20477
Try
<link type="text/css" th:href="@{${DomainUrl + '/web/assets/css/foundation5/foundation.min.css'}}" rel="stylesheet" />
Does ${DomainUrl}
start with http://
or https://
? That makes a difference when creating a link with @{}
expressions.
Upvotes: 0