I am trying out Pebble templating for a config file which is in YAML format. The value for this comes from another YAML file. That is -
- value.yml contains:-
server:
-
box1:
host:"12345"
- config.yml contains:-
server:
-
env: "abc"
host: {{ server.box1.host }}
I could read the config.yml as string and create a Pebble template. Using evaluate I am able to replace the template with context variable whose name is not nested (example {{ serverBox1Host }} --> this works).
If I use {{ server.box1.host }}, I get com.mitchellbosecke.pebble.error.RootAttributeNotFoundException: Root attribute [server] does not exist or can not be accessed and strict variables is set to true. If I set strictVariables as false, the {{ server.box1.host }} is replaced with empty.
How to solve this?
context.put("server.box1.host", "suriya" );
I took references from: https://www.programcreek.com/java-api-examples/?api=com.mitchellbosecke.pebble.PebbleEngine
I am using "String Template":
new PebbleEngine.Builder()
.strictVariables(true)
.newLineTrimming(false)
.loader(new StringLoader())
.build();
Thanks
You can use the dot (.) notation to access attributes of variables that are objects. If the attribute contains any atypical characters, you can use the subscript notation ([]) instead.
Behind the scenes foo.bar will attempt the following techniques to to access the bar attribute of the foo variable:
If foo is a Map,
Additionally, if foo is a List, then foo[0] can be used instead of foo.get(0).
You can take a look at pebble documentation here : https://pebbletemplates.io/wiki/guide/basic-usage/