Search code examples
thymeleaf

Variable in a link


My code:

<script th:text="${theme}">test</script>
<link th:href="@{/themes/${theme}/general/general.css}" rel="stylesheet" />

Result:

<script>holmes</script>
<link href="/themes/${theme}/general/general.css" rel="stylesheet" />

Well, the variable "theme" contains a value. But when it comes to that link creation, we can see ${theme} instead of holmes.


Solution

  • You can use string concatenation like this:

    <link th:href="@{'/themes/'+${theme}+'/general/general.css'}" rel="stylesheet" />