Thymeleaf Component Dialect
A dialect for creating reusable Thymeleaf components with named slots, similar to React or Vue components.
Quick Example
Define a component (templates/components/panel.html):
<div th:fragment="panel(title)" class="card">
<div class="card-header"><b th:text="${title}"></b></div>
<div class="card-body"><tc:content></tc:content></div>
</div>Use it in your template:
<tc:panel tc:constructor="'My Title'">
<p>Hello world</p>
</tc:panel>Result:
<div class="card">
<div class="card-header"><b>My Title</b></div>
<div class="card-body"><p>Hello world</p></div>
</div>Features
- Reusable Components - Define with
th:fragment, use with<tc:*>tags - Named Slots - Multiple content areas per component
- Fallback Content - Default content when no slot is provided
- tc:once - Deduplicate scripts and styles
- Attribute Replacement - Dynamic placeholder values
- Spring Boot Auto-Configuration - Just add the dependency, no setup needed
Installation
Requires Java 17+ and Thymeleaf 3.1+.
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.github.Serbroda</groupId>
<artifactId>thymeleaf-component-dialect</artifactId>
<version>VERSION</version>
</dependency>Spring Boot 3.x: No configuration needed - auto-configured out of the box.
See Getting Started for Gradle setup, custom configuration, and non-Spring Boot usage.
Documentation
- Getting Started - Installation and setup
- Components - Defining and using components
- Named Slots - Multi-slot content projection
- tc:once Attribute - Deduplicate scripts and styles
Contributing
Contributions are welcome! Feel free to open an issue or submit a pull request.
Before submitting a PR, please make sure:
- All tests pass:
./mvnw clean verify - Code is formatted:
./mvnw spotless:apply
License
This project is licensed under the Apache License, Version 2.0.
On this page
Languages
Java88.4%HTML11.6%
Apache License 2.0
Created September 5, 2017
Updated March 21, 2026
