I have created fragments.html file. It contains the following fragment:
<div th:fragment="my_fragment(content)"> <p th:text="${content}"></p> </div> I put the above fragment into my view file:
<div th:replace="fragments :: my_fragment('test')"></div> Now, I want to pass two parameters to my_fragment, but I must ensure backward compatibility.
I tried to solve the problem as follows:
<div th:fragment="my_fragment(content, defaultParameter='default value')"> <p th:text="${content}"></p> </div> Unfortunelly, the above solution generated error:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateProcessingException: Cannot resolve fragment. Signature "my_fragment (content,defaultParameter='default value')" declares 2 parameters, but fragment selection specifies 1 parameters. Fragment selection does not correctly match.
Any idea?