Thymeleaf insert fragment with additional attributes

Viewed 16

Let us suppose to insert a fragment with Thymeleaf:

<div th:insert="templates/fragment.html"> This will be discarded in favour of fragment</div>

Now, I want additionally put

style="......"

In the first tag of the fragment. Is it possible? If yes, can I add an attribute in a specific point within the fragment? In other words is there a way to parametrically add fragments with Thymeleaf?

1 Answers

Insert the fragment with

<div th:insert="templates/fragment.html :: fragName(parameter)">

and then with the fragment I use

th:fragment="fragmName(parameter)"

and

th:attr="style=${parameter}"
Related