
Thymeleaf Tutorial: Chapter 10. Attribute Priority
- Tutorial
Table of contents
What happens when you write more than one th: * attribute in a single tag ? For instance:
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:
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):
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:
Order | Functionality | Attributes |
---|---|---|
1 | Inclusion of fragments | th: insert th: replace |
2 | Fragment Iteration | th: each |
3 | Conditional execution | th: if th: unless th: switch th: case |
4 | Local variable definition | th: object th: with |
5 | Basic attribute modification | th: attr th: attrprepend th: attrappend |
6 | Specific attribute modification | th: value th: href th: src ... |
7 | Text (tag body modification) | th: text th: utext |
8 | Fragment definition | th: fragment |
9 | Delete a fragment | th: 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...