Last active
February 1, 2024 05:13
-
-
Save blinkinglight/b0b099cea4fc6c4f43a1daee8363a6bc to your computer and use it in GitHub Desktop.
This file contains 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 characters
{{ define "htmlbody" }} | |
<h1>Page 1</h1> | |
{{ range .Items }} | |
{{ block "item-row" . }} | |
<div> | |
your page content {{ . }} | |
</div> | |
{{ end }} | |
{{ end }} | |
{{ end }} |
This file contains 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 characters
//go:embed templates/*.html templates/*/*.html | |
var templates embed.FS | |
// <..> | |
func PageTemplate(name string) *template.Template { | |
templs := []string{name, "index.html"} | |
tpl, err := template.New(name).Funcs(/* if any */).ParseFS(templates, templs...) | |
return template.Must(tpl, err) | |
} | |
type VD struct { | |
Data map[string]interface{} | |
} | |
var vd = new(VD); | |
vd.Data["Items"] = []string{"one","two"} | |
PageTemplate("calendar.html").ExecuteTemplate(w, "index.html", vd) | |
// or | |
PageTemplate("calendar.html").ExecuteTemplate(w, "item-row", "one line") |
This file contains 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 characters
<html> | |
<body> | |
<div class="content"> | |
{{ template "htmlbody" . }} | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment