Self referencing templates. #1636
-
I have a single yaml in which is both the datasource and the target. As a very simple example, consider this.
Is such self-referencing datasource and target possible ? If so how do I do it ? Thanks 🙏 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi @blmhemu - this is possible with some slight modification.
key1: val1
key2: val2
key3:
key4: val4
key5: |
1 - {{ .key1 }}
2 - {{ .key2 }}
3.4 - {{ .key3.key4 }} $ gomplate -c .=foo.yaml -f foo.yaml
key1: val1
key2: val2
key3:
key4: val4
key5: |
1 - val1
2 - val2
3.4 - val4 This uses the This works because the file is valid YAML before being processed. Hope this helps! |
Beta Was this translation helpful? Give feedback.
-
Awesome ! Thanks a lot. This answers my original question. In the same vein I have one more question :) -
For ^ this case, should I merge the yamls using a different program (and then use gomplate on the merged file) or would gomplate be able to accomplish the above end-to-end workflow ? |
Beta Was this translation helpful? Give feedback.
Hi @blmhemu - this is possible with some slight modification.
foo.yaml
:This uses the
foo.yaml
file as both a datasource (used as the default context) and the template.This works because the file is valid YAML before being processed.
Hope this helps!