mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 03:55:28 +08:00
add chapter 15.7 (#683)
This commit is contained in:
25
eBook/examples/chapter_15/template_variables.go
Normal file
25
eBook/examples/chapter_15/template_variables.go
Normal file
@@ -0,0 +1,25 @@
|
||||
// template_variables.go
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
func main() {
|
||||
t := template.New("test")
|
||||
t = template.Must(t.Parse("{{with $3 := `hello`}}{{$3}}{{end}}!\n"))
|
||||
t.Execute(os.Stdout, nil)
|
||||
|
||||
t = template.Must(t.Parse("{{with $x3 := `hola`}}{{$x3}}{{end}}!\n"))
|
||||
t.Execute(os.Stdout, nil)
|
||||
|
||||
t = template.Must(t.Parse("{{with $x_1 := `hey`}}{{$x_1}} {{.}} {{$x_1}}{{end}}!\n"))
|
||||
t.Execute(os.Stdout, nil)
|
||||
}
|
||||
|
||||
/* Output:
|
||||
hello!
|
||||
hola!
|
||||
hey hey hey!
|
||||
*/
|
Reference in New Issue
Block a user