stencil.ApplyTemplate
ApplyTemplate executes a named template (defined through the define
function) with the provided optional data.
The provided data can be accessed within the defined template under the .Data
key.
.
is a copy of Valuesfor the calling template, meaning it is not mutated to reflect that of the template being rendered.
Examples
Without Data
go
{{- define "command"}}
package main
import "fmt"
func main() {
fmt.Println("hello, world!")
}
{{- end }}
{{- stencil.ApplyTemplate "command" | file.SetContents }}
With Data
go
{{- define "command"}}
{{- $cliName := .Data }}
package main
import "fmt"
func main() {
fmt.Println("hello from {{ $cliName }}!")
}
{{- end }}
{{- range $cliName := stencil.Arg "clis" }}
{{- stencil.ApplyTemplate "command" $cliName | file.SetContents }}
{{- end }}