mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 05:11:49 +08:00
22 lines
335 B
Go
22 lines
335 B
Go
// template_with_end.go
|
|
package main
|
|
|
|
import (
|
|
"os"
|
|
"text/template"
|
|
)
|
|
|
|
func main() {
|
|
t := template.New("test")
|
|
t, _ = t.Parse("{{with `hello`}}{{.}}{{end}}!\n")
|
|
t.Execute(os.Stdout, nil)
|
|
|
|
t, _ = t.Parse("{{with `hello`}}{{.}} {{with `Mary`}}{{.}}{{end}}{{end}}!\n")
|
|
t.Execute(os.Stdout, nil)
|
|
}
|
|
|
|
/* Output:
|
|
hello!
|
|
hello Mary!
|
|
*/
|