Thymeleaf Tutorial: Chapter 10. Attribute Priority

  • Tutorial
Table of contents

10 Attribute Priority


What happens when you write more than one th: * attribute in a single tag ? For instance:

  • Item description here...

We expect that the th: each attribute will be executed before th: text so that we get the desired results, but given the fact that the HTML / XML standards do not matter for the order of the attribute in the tag, the priority mechanism must be set in the attributes themselves to be sure that it will work as expected.

Thus, all Thymeleaf attributes define a numerical value that sets the order in which they are executed in the tag. This order:

OrderFunctionalityAttributes
1Inclusion of fragmentsth: insert
th: replace
2Fragment Iterationth: each
3Conditional executionth: if
th: unless
th: switch
th: case
4Local variable definitionth: object
th: with
5Basic attribute modificationth: attr
th: attrprepend
th: attrappend
6Specific attribute modificationth: value
th: href
th: src
...
7Text (tag body modification)th: text
th: utext
8Fragment definitionth: fragment
9Delete a fragmentth: remove

This priority mechanism means that the above iteration fragment will give exactly the same results if the attribute position is inverted (although it will be slightly less readable):

  • Item description here...

Also popular now: