go - With Golang Templates how can I set a variable in each template? -
how can set variable in each template can use in other templates e.g. {{ set title "title" }} in 1 template in layout <title> {{ title }} </title> then when it's rendered tmpl, _ := template.parsefiles("layout.html", "home.html") it set title according whatever set in home.html instead of having make struct each view page when isn't necessary. hope made sense, thanks. just clarification: layout.html: <!doctype html> <html> <head> <title>{{ title }} </title> </head> <body> </body> </html> home.html: {{ set title "home" . }} <h1> {{ title }} page </h1> if want use value in template can pipeline dot: {{with $title := "sometitle"}} {{$title}} <--prints value on page {{template "body" .}} {{end}} body template: {{define "body"}} <h1>{{.}}</h1> <--prints "sometitle...