Bikash Sahoo
Bikash Sahoo

Reputation: 95

Spring Thymeleaf expression is not working

Can anyone please point out the problem i am facing while passing values through context to a templateEngine please.

<img th:src="${serverURL}/support-images/logo.jpg" height="54" width="108" alt=""></img>

"${serverURL}" : supposed to give me the complete URL where my application is hosted. The error i am getting is "Could not parse as expression: "${serverURL}/support-images/logo.jpg""

It make me realized something is wrong in the syntax but i could not follow the articles available. Can anyone please help!!

Thanks!!

Upvotes: 1

Views: 843

Answers (1)

Nicolas
Nicolas

Reputation: 2231

You mix literals and expressions in your attribute. You should probably write <img th:src="${serverURL}+'/support-images/logo.jpg'" height="54" width="108" alt=""></img> for it to work better. See the examples in the documentation.

You may also want to read about the link URL feature in Thymeleaf (@{} notation) that can assist when building URLs.

Upvotes: 3

Related Questions