I am using below code to create a dynamic template -
Engine engine = Engine.builder().addDefaults().build();
Template t = engine.parse(" Dear:Your {obj.name}", null, "something");
Body obj = new Body();
obj.name = "ABC";
t.data("obj",obj).render()
I expect Dear:Your ABC as a result of the render. Instead I get, Dear:Your NOT_FOUND
If I do something like below it works as expected -
Template t = engine.parse(" Dear:Your {name}", null, "something");
t.data("name",name).render()
Somehow when qute templates are created with engine.parse, they are not able to understand the object as data. If I use the same contect with the html file injection as -
@Inject
Template something;
something.data("obj",obj).render();
This renders as expected. Any idea what am I doing wrong?
After many hours of going through the documentation (very little available) and bit of source code, I think I finally found the answer.
Only thing I had to do is use the existing engine instance by injecting instead of crating a new one.
Replacing -
Engine engine = Engine.builder().addDefaults().build(); with
@Inject
Engine engine;
works fine for me.
Just posting here if it helps anyone else in the same boat.