Search⌘ K
AI Features

Layouts with Parameters

Explore how to define and use parameterized layouts in Thymeleaf. Understand creating fragments that accept parameters to customize appearance and content, enabling more reusable and flexible templates for scalable applications.

We'll cover the following...

Layouts can have parameters, just like fragments. To show how this works, we will create an admonition fragment:

HTML
<!DOCTYPE html>
<html
xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
>
<body>
<!--/*@thymesVar id="type" type="java.lang.String"*/-->
<div
layout:fragment="admonition(type)"
class="flex mb-4 p-2 w-2/4"
th:classappend="${type == 'NOTE'?'bg-yellow-100':'bg-blue-100'}"
>
<div th:text="${type}" class="mr-4"></div>
<div layout:fragment="message"></div>
</div>
</body>
</html>

Defining the

...