This question is in continuation with earlier question I have posted before.
To enhance my templates further I need to have multiple loops in the template engines and the values need to be replaced from the HashMap Variables that were derived from a configuration file.
My HashMap looks something like this, let say envVar
:
envVar = [
PROJECT:name,
env:[
[name:param1, value:value1],
[name:param2, value:value2],
[name:param3, value:value3]],
ports:[
[protocol:port1, port:1000],
[protocol:port2, port:2000]]
]
My template engine looks like this:
- env:
<< NEED TO LOOP HERE WITH env variables
- name : param1
value : value1
....
>>
project: "${PROJECT}"
......
......
......
ports:
<< NEED TO LOOP HERE WITH ports variables
- port: 1000
protocol : port1
....
>>
Code snippet is described below.
def f = new File('output.template')
def engine = new groovy.text.GStringTemplateEngine()
//....
//envVar are derived from another file
//....
def Template = engine.createTemplate(f).make(envVar)
println "${Template}"
Can someone explain me how to modify the above code snippet and templates to make sure the envVar will be replaced properly in the template engine.