mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 04:46:22 +08:00
add chapter 15.7 (#683)
This commit is contained in:
21
eBook/examples/chapter_15/template_with_end.go
Normal file
21
eBook/examples/chapter_15/template_with_end.go
Normal file
@@ -0,0 +1,21 @@
|
||||
// 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!
|
||||
*/
|
Reference in New Issue
Block a user