Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to assign more than one attribute to the html element with thymeleaf

I have a select box on my thymelaf page. I already have defined one attribute for it like:

th:attr="labelId='associateTSF' + ${mViewStat.index}" 

Is there a way to set more than one? something like:

th:attr="labelId='associateTSF' + ${mViewStat.index}; missionGroup=${mView.missionGroup}" 

I have already tried this with ; and with blank space, no success. All examples I have found are with single value.

Thanks!

like image 724
Djordje Ivanovic Avatar asked Mar 31 '14 18:03

Djordje Ivanovic


People also ask

How do you add Thymeleaf to HTML?

html file should be placed under the templates directory and all JS and CSS files should be placed under the static directory in classpath. In the example shown, we used CSS file to change the color of the text. Now, we need to add the Spring Boot Starter Thymeleaf dependency in our build configuration file.

What does th stand for in Thymeleaf?

This is the default behaviour of the th:text attribute. If we want Thymeleaf to respect our XHTML tags and not escape them, we will have to use a different attribute: th:utext (for “unescaped text”): <p th:utext="#{home.welcome}">Welcome to our grocery store!</

What is th block Thymeleaf?

th:block is a Thymeleaf element rather than an attribute, and it has the general syntax: 1 2 3. <th:block> <!-- Your HTML code --> </th:block> th:block allows you to apply the same Thymeleaf attribute, like th:if or th:each to a block of code.


2 Answers

Found it! And it works. It should be separated by comma.

HTML forbids repeated attributes, so that code is not correct. However, th:attr and data-th-attr allow you to specify several attributes separated by commas, like:

 <a href="#"     data-th-attr="data-groupid=${somevalue},                   data-groupname=${someothervalue}">...</a> 

found it on this discussion: https://github.com/thymeleaf/thymeleaf/issues/93

like image 186
Djordje Ivanovic Avatar answered Oct 01 '22 14:10

Djordje Ivanovic


This worked for me

th:attr="attrParam1=${attrVal1},           width=${width != null ? width : null},           height=${height != null ? height : null}" 
like image 23
utkusonmez Avatar answered Oct 01 '22 12:10

utkusonmez