Tom Tom - 3 months ago 48x
Java Question

thymeleaf - combined th:each with th:href

I'm new to Thymeleaf (and webdev) and I'm trying to combine Thymeleaf iteration (th:each) with URL re-writing (th:href).

<a th:each="lid : ${lists}" th:text="${lid}" th:href="@{/list?l=${lid}}">

This produces the following (where lid=45):

<a href="/list?l=${lid}">45</a>

So, it did the substitution on the th:text, but not on the th:href.

I'm not trying to do any sort of URL re-writing, I'm just using the '@' syntax because I want Thymeleaf to substitute the 'lid' attribute.

I'm using the current version of Thymeleaf (2.1.2) with Google App Engine.


If you don't want to do any url rewriting, you shouldn't use the @ syntax.

You can use the pipeline (|) syntax to do some literal substitions:


Source: Thymeleaf documentation