Reputation: 86757
Is it possible to create a fragment in Thymeleaf taking optional arguments?
<div th:fragment="personfragment(name, age, optionalargs...)">
So I could call it with either:
<div th:replace="personfragment('john', '28', 'arg1')" />
<div th:replace="personfragment('john', '28', 'arg1', 'arg2', 'arg3')" />
This is not a duplicate, as I don't know the number of args beforehand. That's what optional arguments are for: not having to set the number or arguments!
I'd also be happy if someone knows how to pass parameters just as an array-parameter?
Upvotes: 1
Views: 1519
Reputation: 652
Use a single parameter that is an object.
You can then inspect the object inside your fragment and extract the relevant properties if they exist.
Upvotes: 1