Process datasources as templates before the final template #2151
-
Hi, I'm currently using the 3.11.7 version for homemade scripts. I am using it with some YAML datasources. I am facing a recurrent issue and maybe I am missing something in the documentation. Suppose I have this YAML datasource: ---
# awesome.yaml
my_awesome_map:
first: 'this string is awesome'
second: '{{ (datasource "awesome").my_awesome_map.first }}ly awesome'
... when using this command line:
It is printing:
Which is indeniably correct.
Currently, the solution I have is to use gomplate to resolve the awesome.yaml file with itself as datasource before. But I have to repeat this operation for each dependencies in my datasources. Does it exist a way to make gomplate prints the result I am expecting with a unique execution ? If not, do you think it is something that we can see in the gomplate roadmap? Thank you for this awesome tool. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
@tiawl Thanks for filing this - I've converted this to a discussion topic since it's neither a bug report nor a feature request. What you're looking for is nested templates - see the docs: I think that'll answer your question, but let me know if you have any more questions around how these work. |
Beta Was this translation helpful? Give feedback.
Are you trying to use the nested template itself as a datasource? I'm a bit confused about that...
One thing you may want to also look at is the
tmpl.Exec
function - see https://docs.gomplate.ca/functions/tmpl/#tmplexecAnd re: the environment variables -
template
doesn't inherit the context unless you explicitly tell it to - like{{ template "user" . }}
.But perhaps a cleaner approach would be to use
getenv
instead