Search⌘ K

Fragments with Parameters

Explore how to use parameters in Thymeleaf fragments to create flexible and reusable HTML components, making your Spring Boot application easier to maintain and expand.

We'll cover the following...

Parameters

Just like simple functions or methods in programming, our Thymeleaf fragments can also have parameters. For example, say we want to have a menu item with title and link as parameters:

HTML
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<body>
<a th:fragment="menu-item(title, link)"
th:text="${title}"
th:href="${link}"
class="flex items-center px-2 py-2 text-base leading-6 font-medium text-gray-900">
</a>
</body>
</html>

For example, we can use ...