Files
the-way-to-go_ZH_CN/eBook/examples/chapter_15/template_variables.go
2013-05-07 23:43:09 -04:00

25 lines
468 B
Go

// 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!
*/