Thymeleaf syntax expressions¶
Thymeleaf provides a comprehensive set of expression syntaxes designed to handle variables, internationalization, URLs, and fragments within templates^[600-developer-java-spring-thymeleaf-spring-thymeleaf-01.md].
Expression Objects¶
Thymeleaf defines specific variable expressions starting with specific symbols to perform distinct operations^[600-developer-java-spring-thymeleaf-spring-thymeleaf-01.md]:
${...}(OGNL): Used for Object-Graph Navigation Language (OGNL) expressions to retrieve variable values^[600-developer-java-spring-thymeleaf-spring-thymeleaf-01.md].- *
*{...}(Selection)**: Used to select properties from a specific object, often used in conjunction with a form backing object (e.g.,{object.xxx}`)^[600-developer-java-spring-thymeleaf-spring-thymeleaf-01.md].
Utility Expressions¶
Beyond variable access, specific syntaxes are provided for localization, linking, and template composition^[600-developer-java-spring-thymeleaf-spring-thymeleaf-01.md]:
#{...}: Used for retrieving internationalized messages^[600-developer-java-spring-thymeleaf-spring-thymeleaf-01.md].@{...}: Used to define URL paths, which can include context paths or query parameters^[600-developer-java-spring-thymeleaf-spring-thymeleaf-01.md].~{...}: Used to reference fragment expressions, allowing for the insertion of reusable template parts^[600-developer-java-spring-thymeleaf-spring-thymeleaf-01.md].
Attribute Manipulation¶
Thymeleaf can replace standard HTML attributes to enable dynamic processing^[600-developer-java-spring-thymeleaf-spring-thymeleaf-01.md]. For example, the th:id attribute is capable of completely replacing the standard HTML id attribute^[600-developer-java-spring-thymeleaf-spring-thymeleaf-01.md].
Related Concepts¶
- Spring Boot
- [[Templating engines]]
- [[Internationalization (i18n)]]
Sources¶
^[600-developer-java-spring-thymeleaf-spring-thymeleaf-01.md]