template_with_end.go 335 B

123456789101112131415161718192021
  1. // template_with_end.go
  2. package main
  3. import (
  4. "os"
  5. "text/template"
  6. )
  7. func main() {
  8. t := template.New("test")
  9. t, _ = t.Parse("{{with `hello`}}{{.}}{{end}}!\n")
  10. t.Execute(os.Stdout, nil)
  11. t, _ = t.Parse("{{with `hello`}}{{.}} {{with `Mary`}}{{.}}{{end}}{{end}}!\n")
  12. t.Execute(os.Stdout, nil)
  13. }
  14. /* Output:
  15. hello!
  16. hello Mary!
  17. */