...

/

Layouts with Parameters

Layouts with Parameters

Learn to use parameters in layout.

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

<!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 fragment

Since we want to only use the <div> and it’s ...