If you want to use the value in another template, you can associate it with a dot:
{{with $title := "SomeTitle"}} {{$title}} <--prints the value on the page {{template "body" .}} {{end}}
body pattern:
{{define "body"}} <h1>{{.}}</h1> <--prints "SomeTitle" again {{end}}
As far as I know, it is impossible to move up the chain. This way layout.html is output before home.html , so you cannot pass the value back.
In your example, it would be a better solution to use a structure and pass it from layout.html to home.html using dot :
main.go
package main import ( "html/template" "net/http" ) type WebData struct { Title string } func homeHandler(w http.ResponseWriter, r *http.Request) { tmpl, _ := template.ParseFiles("layout.html", "home.html") wd := WebData{ Title: "Home", } tmpl.Execute(w, &wd) } func pageHandler(w http.ResponseWriter, r *http.Request) { tmpl, _ := template.ParseFiles("layout.html", "page.html") wd := WebData{ Title: "Page", } tmpl.Execute(w, &wd) } func main() { http.HandleFunc("/home", homeHandler) http.HandleFunc("/page", pageHandler) http.ListenAndServe(":8080", nil) }
layout.html
<!DOCTYPE html> <html> <head> <title>{{.Title}} </title> </head> <body> {{template "body" .}} </body> </html>
home.html
{{define "body"}} <h1>home.html {{.Title}}</h1> {{end}}
page.html
{{define "body"}} <h1>page.html {{.Title}}</h1> {{end}}
You also have some good documentation on how to use templates:
http://golang.org/pkg/text/template/