Skip to content

Instantly share code, notes, and snippets.

@krishbhanushali
Last active April 7, 2021 20:00
Show Gist options
  • Save krishbhanushali/cdba07c391bb1a311503069502299c0d to your computer and use it in GitHub Desktop.
Save krishbhanushali/cdba07c391bb1a311503069502299c0d to your computer and use it in GitHub Desktop.
{{template "header" }} {{block "listOfItems" .}}Hello, this is the list of items. {{end}} {{template "footer"}}
{{define "header"}} This is the header {{end}}
{{define "listOfItems"}}
{{range .}}
{{println "-" .}}
{{end}}
{{end}}
package main
import (
"log"
"os"
"text/template"
)
func main() {
var items = []string{"item A", "item B", "item C", "item D", "item E"}
t, err := template.New("full.tmpl").ParseFiles("full.tmpl", "header.tmpl", "list_of_items.tmpl", "footer.tmpl")
if err != nil {
log.Panic(err)
}
err = t.Execute(os.Stdout, items)
if err != nil {
log.Panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment