Debian Codegraph @

util/sprig/example_test.go

raw
1 package sprig
2
3 import (
4 "fmt"
5 "os"
6 "text/template"
7 )
8
9 func Example() {
10 // Set up variables and template.
11 vars := map[string]any{"Name": " John Jacob Jingleheimer Schmidt "}
12 tpl := `Hello {{.Name | trim | lower}}`
13
14 // Get the Sprig function map.
15 fmap := TxtFuncMap()
16 t := template.Must(template.New("test").Funcs(fmap).Parse(tpl))
17
18 err := t.Execute(os.Stdout, vars)
19 if err != nil {
20 fmt.Printf("Error during template execution: %s", err)
21 return
22 }
23 // Output:
24 // Hello john jacob jingleheimer schmidt
25 }