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

Global variables in the sub-templates #283

Open
artemklevtsov opened this issue Dec 6, 2024 · 0 comments
Open

Global variables in the sub-templates #283

artemklevtsov opened this issue Dec 6, 2024 · 0 comments

Comments

@artemklevtsov
Copy link

artemklevtsov commented Dec 6, 2024

Hi,

How can I pass global variables to the sub-templates?

Example:

{{- set $ "global" "text" }}
{{ $.global }}
{{ $v := dict "key" "value" }}

{{ template "T1" $v }}
{{- define "T1" }}
{{ $.global }}
{{ .key }}
{{- end }}

Result:

❯  gotemplate --print main.template
template: main.template:: contains undefined value(s)
1 
2 text
3 
4 
5 
6 <no value>
7 value
8 

The same with include function.

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

1 participant