Created
August 28, 2015 07:04
Revisions
-
jonathaningram created this gist
Aug 28, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ Question: could the child/overlay/aboutPage get the default content from the master with something like `{{parent}}` or `{{master}}`? E.g. ```golang 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}}` ) ``` This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ 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>