thymeleaf / thymeleaf-docs

Thymeleaf documentation
Apache License 2.0
44 stars 54 forks source link

Code error in the "Extending Thymeleaf" tutorial #59

Closed xtianus closed 6 years ago

xtianus commented 6 years ago

I think there is a mistake in the 3.2 section. The first code example is showing how to add a class to a tag:

if (attributeValue != null) {
    structureHandler.setAttribute("class", attributeValue + " " + newValue);

The attributeValue, though, is not the current class value but (I think) the current tag value. The correct code should be

String currentClass = tag.getAttribute("class").getValue();
if (currentClass != null) {
    structureHandler.setAttribute("class", currentClass + " " + newValue);
ultraq commented 6 years ago

I think you're right: attributeValue is the value given to the tag processor, which in the examples is the iteration expression ${tStat.count} and not the current class.

I'll apply your correction to our docs soon. Thanks for letting us know! 👍