Golang templates with Nested variables

Hi,

In my first version i have just implemented a function to interpolate something like this:

"{{ .house }} {{ .cosa_rara | upper }} " using the next maps:

varsContent := map[string]interface{}{
“mix”: "{{ .house }} {{ .cosa_rara | upper }} ",
“house”: “A {{ .the }} casita”,
“the”: “la {{ .cosa_rara | title }}”,
“animal”: “de {{ .the | title }} mariposa”,
“cosa_rara”: “demo_pato”,
“mapa”: “demo_pato”,
“cyclic”: “This is a {{ .cyclic }}”,
“colour”: map[string]interface{}{
“red”: “rojo”,
“blue”: “azul”,
“pink”: “rosa”,
“orange”: “{{ mapa }}”,
},
}

The result of this execution is: "A la Demo_pato casita DEMO_PATO ". As you can see, the interpolation is executed recursively and works fine. My problem now is implement a way to exectue this: “{{ .colour.orange }}”, the result of this execution should be “demo_pato” and in this point… I need help.

Thank you very much.

Hi, Jose, do you have a link to the code?

Hi,

This is the test https://github.com/judoDsl/interpolator/blob/40d981f685b1447ae1a1720bd0e3c2f18d9973c7/main_test.go#L129.

Thank you!!

My apologies, I think I just found a much easier solution. Thank you for your time !!!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.