Skip to content

Instantly share code, notes, and snippets.

@jonathaningram
Created August 28, 2015 07:04
Show Gist options
  • Save jonathaningram/0bf987b3f4aa244476d5 to your computer and use it in GitHub Desktop.
Save jonathaningram/0bf987b3f4aa244476d5 to your computer and use it in GitHub Desktop.

Question: could the child/overlay/aboutPage get the default content from the master with something like {{parent}} or {{master}}?

E.g.

const (
    layout  = `<title>{{block "metaTitle" .}}golang.org{{end}}</title><body>{{block "content"}}{{end}}</body>`
    aboutPage = `{{define "metaTitle"}}Read all about Go - {{parent}}{{end}} {{define "content"}}About page content{{end}}`
)
const (
layout = `<title>{{block "metaTitle" .}}Welcome to golang.org{{end}}</title><body>{{block "content"}}{{end}}</body>`
aboutPage = `{{define "metaTitle"}}Read all about Go on golang.org{{end}} {{define "content"}}About page content{{end}}`
)
layoutTmpl, err := template.New("layout").Parse(layout)
if err != nil {
log.Fatal(err)
}
aboutPageTmpl, err := layoutTmpl.Overlay(aboutPage)
if err != nil {
log.Fatal(err)
}
if err := layoutTmpl.Execute(os.Stdout, nil); err != nil {
log.Fatal(err)
}
if err := aboutPageTmpl.Execute(os.Stdout, nil); err != nil {
log.Fatal(err)
}
// Output:
// <title>Welcome to golang.org</title><body></body>
// <title>Read all about Go on golang.org</title><body>About page content</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment