Skip to content

Self referencing templates. #1636

Answered by hairyhenderson
blmhemu asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @blmhemu - this is possible with some slight modification.

foo.yaml:

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 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!

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by blmhemu
Comment options

You must be logged in to vote
2 replies
@hairyhenderson
Comment options

@blmhemu
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants