Fragments with Parameters
Learn how to incorporate parameters in Fragments.
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:
Press + to interact
<!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 this ...