example_test.go 518 B

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