vakho10/Java-Spring-Boot-with-Web-Flow-and-Thymeleaf

Trying to add static variable

Closed this issue · 3 comments

I have downloaded your example and was able to get it running using gradle. Great example! Very hard finding a working example. So, I've tried adding a static variable, which I cannot seem to get working.

In the config file, I the thymeleafViewResolver method, I am trying to add the static variable, viewResolver.addStaticVariable("currentYear", Year.now());, where the currentYear is displayed in the footer as the copyright year. When I try to use the variable in one of the html page, it does not display. Is this not the proper way to define a static variable? Is there another way to define global variables other than creating a parent Model class?

@sandman202 Hi, are you echoing the output like this?
<p th:text="${date}"></p>
It works for me :)

Yes, that worked. I am using inlining and forgot to add it in the div.

@sandman202 Glad to hear it 👍