Reputation: 280
I want to insert an attribute into the HTML Code.
I tried this, but it's not working:
<div id="${var}"> ... </div>
I think you know what I mean. The attribute var
should be the ID
. I didn't find a solution...
Upvotes: 0
Views: 1846
Reputation: 20487
Thymeleaf only evaluates attributes that are prefixed with th:
. Here is a list of the attributes that are evaluated:
http://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#setting-value-to-specific-attributes
In your case, th:id
is already built in so you can simply do <div th:id="${var}"> ... </div>
and it will work. th:attr
, is used to define attributes that thymeleaf doesn't normally support.
Upvotes: 0
Reputation: 16106
You just need to use the th:attr
attribute. It is explained in the reference documentation 5.1:
Enter then the th:attr attribute, and its ability to change the value of attributes of the tags it is set in:
<form action="subscribe.html" th:attr="action=@{/subscribe}"> <fieldset> <input type="text" name="email" /> <input type="submit" value="Subscribe!" th:attr="value=#{subscribe.submit}"/> </fieldset> </form>
The concept is quite straightforward: th:attr simply takes an expression that assigns a value to an attribute. Having created the corresponding controller and messages files, the result of processing this file will be:
<form action="/gtvg/subscribe"> <fieldset> <input type="text" name="email" /> <input type="submit" value="¡Suscríbe!"/> </fieldset> </form>
Upvotes: 3