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

Djordje Ivanovic picture Djordje Ivanovic · Mar 31, 2014 · Viewed 13.5k times · Source

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!

Answer

Djordje Ivanovic picture Djordje Ivanovic · Mar 31, 2014

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