Last active
April 7, 2021 20:00
-
-
Save krishbhanushali/cdba07c391bb1a311503069502299c0d 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
{{template "header" }} {{block "listOfItems" .}}Hello, this is the list of items. {{end}} {{template "footer"}} |
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 "header"}} This is the header {{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
{{define "listOfItems"}} | |
{{range .}} | |
{{println "-" .}} | |
{{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
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