Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic: template: template:19:25: executing "template" at <.Env>: map has no entry for key "Env" #160

Closed
estahn opened this issue Jun 13, 2017 · 3 comments

Comments

@estahn
Copy link

estahn commented Jun 13, 2017

Using .Env within range produces the following error:

panic: template: template:19:25: executing "template" at <.Env>: map has no entry for key "Env"

Example:

{{ range (datasource "gomplate").foobar }}
{{ .Env.FOOBAR }}
{{ end }}
@hairyhenderson
Copy link
Owner

Ah. yep. This is because the meaning of . changes within range. Probably the simplest way to resolve this is by using getenv instead of .Env:

{{ range (datasource "gomplate").foobar }}
{{ getenv "FOOBAR" }}
{{ end }}

@estahn
Copy link
Author

estahn commented Jun 13, 2017

Yes, that's what I've done. But I would have liked the fail-feature in case a variable is not set :)

@estahn estahn closed this as completed Jun 13, 2017
@hairyhenderson
Copy link
Owner

@estahn ah - well another option could be something like:

{{ $root := . }}
{{ range (datasource "gomplate").foobar }}
{{ $root.Env.FOOBAR }}
{{ end }}

Hope that helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants