A
A
Alecxandrys2017-10-11 15:05:41
Spring
Alecxandrys, 2017-10-11 15:05:41

How to pass parameter to fragment?

Good afternoon, It is
necessary to pass a parameter to it when embedding a fragment. The Thymeleaf template engine is used, the application itself is based on Spring (if it matters).
Fragment initiation code

<html th:fragment="navbar (template, menu, head)" xmlns:th="http://www.thymeleaf.org">

Call from page
<html xmlns:th="http://www.thymeleaf.org" th:replace="~{fragments/NavBar :: navbar (~{::body},${param.room},~{::head})}">>

The problem occurs with the ${param.room} parameter. This is a regular method of pulling the value from the URL (?room=room_value) from the template engine, further on the page it works properly, but in this call it is not passed as a parameter to the fragment. If it is replaced with the line:
<html xmlns:th="http://www.thymeleaf.org" th:replace="~{fragments/NavBar :: navbar (~{::body},'Параметр',~{::head})}">>

then the value "Parameter" is successfully passed.
How to pass the parameter correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2017-10-11
@Alecxandrys

You can try to use preprocessing :
or remove this parameter and just use it ${param.room}in the included fragment.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question