Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set global variable in thymeleaf?

Tags:

thymeleaf

I am using thymeleaf in front end and I know variable concept in thymeleaf

<span th:with="var=${someValue}" th:text="${var}"></span>

if I use th:text the value in the variable will be printed and I can use that variable in the same element, Is there any way to use the var in other element like

<span th:with="var=${someValue}"></span>

<span th:text="${var}"></span>

I need to provide global scope to that variable is it possible in thymeleaf ?

like image 814
subbu royal Avatar asked May 19 '16 12:05

subbu royal


2 Answers

Define var in the opening body tag

<body th:with="var=${var_value}">
like image 96
Moses Koledoye Avatar answered Oct 19 '22 18:10

Moses Koledoye


Only nested item can see variable. Div tag is only an example. You can use tags you wants

<div th:with="var=${var_value}">

  inside div tag var is visible.

</div>
like image 38
Gabriele Piacentini Avatar answered Oct 19 '22 20:10

Gabriele Piacentini