Why Thymeleaf tags are being interpreted as text instead of being processed?

These days I came across Thymeleaf.  It seemed a wonderful template engine so I started playing with it.

I created a tiny project which involved just a template and some messages (for internationalization).

I came across a (newbie) problem: Thymeleaf wasn’t processing my messages.

The content of my messages.properties file was

And my template was as simple as this:

So I was expecting to see the following imageworking-thymeleaf

But (for my deception) the result page I saw was this one:not-working-thymeleaf

I got a bit puzzled with the result:

  • Why in the heaven, Thymeleaf is not processing its th:text commands?
  • Why are the commands been interpreted literally?

After scratching my head for some time I figured out what was my error.

Thymeleaf doesn’t indiscriminately substitute text inside the HTML tags. Say, it won’t replace the text from

It will replace from tags when it’s instructed to do so and we do instruct it by putting the th:text=”#{}” commands inside the tag itself. Not in the place reserved for its value.

So, instead of write

I should have written

Did you noticed the difference?

So, in case you have the same problem as I did, be sure you wrote the Thymeleaf’s commands in the right place.

Below is my full code that worked fine:

By the way, Thymeleaf is really a great template engine. I highly recommend it.

Please, try my games, play free on-line games on my site, tweet this post url and share it on facebook, google+ and other social medias.

This entry was posted in development, web and tagged , . Bookmark the permalink.