Thymeleaf attribute processor¶
A Thymeleaf attribute processor is a specific syntax in the Thymeleaf template engine used to evaluate expressions and modify standard HTML attributes within a template.^[600-developer__java__spring__thymeleaf__spring-thymeleaf-01.md]
Syntax and Capabilities¶
Attribute processors in Thymeleaf are denoted by the th: prefix, followed by a specific attribute name.^[600-developer__java__spring__thymeleaf__spring-thymeleaf-01.md]
The th:id processor is one specific example of an attribute processor^[600-developer__java__spring__thymeleaf__spring-thymeleaf-01.md]. Like other processors, it possesses the capability to replace the entire corresponding standard attribute in the HTML tag^[600-developer__java__spring__thymeleaf__spring-thymeleaf-01.md].
Supported Expressions¶
Thymeleaf attribute processors utilize specific expression syntaxes to handle different types of logic:
- Variable Expressions (
${}): Often referred to as OGNL, these are used to access variables from the context^[600-developer__java__spring__thymeleaf__spring-thymeleaf-01.md]. - Selection Expressions (
*{}): Used to select a specific object, such as*{object.xxx}^[600-developer__java__spring__thymeleaf__spring-thymeleaf-01.md]. - Message Expressions (
#{}): Used for internationalization (i18n) and externalizing text^[600-developer__java__spring__thymeleaf__spring-thymeleaf-01.md]. - Link URL Expressions (
@{}): Used to construct URLs and web application paths^[600-developer__java__spring__thymeleaf__spring-thymeleaf-01.md]. - Fragment Expressions (
~{}): Used to reference fragments of other templates^[600-developer__java__spring__thymeleaf__spring-thymeleaf-01.md].
Related Concepts¶
- [[Thymeleaf]]
- [[Template Engine]]
- Spring Boot