Passing variables to nested templates #1731
Replies: 3 comments 1 reply
-
You'd need to pass that value in to the nested template's context. Your template would then need to refer to it as Also there's a scoping bug in your template currently - when you use The final template would look something like:
Within the
or, just:
If you want to pass multiple values through, use |
Beta Was this translation helpful? Give feedback.
-
Thanks I'll take a look at the referenced docs
…On Thu, May 11, 2023, 4:33 PM Dave Henderson ***@***.***> wrote:
You'd need to pass that value in to the nested template's context. Your
template would then need to refer to it as . or .something.
Also there's a scoping bug in your template currently - when you use :=
that declares and defines the variable within that scope (the if block,
in this case), so it won't be able to be referenced in the tmpl.Inline
line. Instead, declare it with :=, then redefine it with =.
The final template would look something like:
{{ $helpDeskEmail := "" -}}
{{- if and (has .pkg "blueprint") (has .pkg.blueprint "helpDeskEmail") -}}
{{- $helpDeskEmail = .pkg.blueprint.helpDeskEmail -}}
{{- else -}}
{{- $helpDeskEmail = .global.helpDeskEmail -}}
{{- end -}}
{{- tmpl.Inline (include "git" "docs/CONTRIBUTING-header.md.tmpl") $helpDeskEmail -}}
Within the docs/CONTRIBUTING-header.md.tmpl you could read that context:
{{ $helpDeskEmail := . -}}
The helpdesk e-mail is: {{ $helpDeskEmail }}
*or, just:*
The helpdesk e-mail is: {{ . }}
If you want to pass multiple values through, use dict. See the examples
in the tmpl.Inline docs
<https://docs.gomplate.ca/functions/tmpl/#tmplinline>.
—
Reply to this email directly, view it on GitHub
<#1731 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AOJRHXPMZ7DD4775ZPAR6VDXFVEIFANCNFSM6AAAAAAX5WMZAQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***
com>
|
Beta Was this translation helpful? Give feedback.
-
Hey @hairyhenderson -- do you know why the following code:
Exits with the following error:
|
Beta Was this translation helpful? Give feedback.
-
Hey, I have a template that includes a bunch of partials and I'd like to define variables to use just once. My template looks like this:
Then, in the included template, I'd like to be able to use
{{ $helpDeskEmail }}
. How can I accomplish this?Beta Was this translation helpful? Give feedback.
All reactions