Skip to content
Advertisement

Thymeleaf – output variable without a tag

I use Thymeleaf as a templating engine and I usually output variable value like this:

in Java I set:

JavaScript

and in html template I output:

JavaScript

This works great, but I would like to output a variable without the need of a tag. Something following would be great:

JavaScript

Unfortunately it does not work. My goal is to avoid unnecessary tag to output the variable value. Is this possible to do with Thymeleaf?

Advertisement

Answer

My goal is to avoid unnecessary tag to output the variable value. Is this possible to do with Thymeleaf?

Yes this is possible. You can use the Thymeleaf synthetic th:block tag (see here).

Example template excerpt:

JavaScript

This renders the following HTML:

JavaScript

Only the variable is displayed.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement