Golang html/template.ParseGlob function examples
package html/template
ParseGlob creates a new Template and parses the template definitions from the files identified by the pattern (1st parameter), which must match at least one file. The returned template will have the (base) name and (parsed) contents of the first file matched by the pattern. ParseGlob is equivalent to calling ParseFiles with the list of files matched by the pattern.
Golang html/template.ParseGlob function usage examples
Example 1:
wd, err := os.Getwd()
source := filepath.Join(wd, "bootstrap")
pattern := filepath.Join(wd, "templates", "*.html")
set = template.Must(template.ParseGlob(pattern))
Example 2:
t = template.ParseGlob("./templates/*.tmpl")
templates = template.Must(template.ParseGlob("views/*.tmpl"))
Example 3:
HTML = html.Must(html.ParseGlob(config.TemplatesDir + "/*.html"))
TEXT = text.Must(text.ParseGlob(config.TemplatesDir + "/*.txt"))
References :
Advertisement
Something interesting
Tutorials
+14.1k Golang : Check if a file exist or not
+15.6k Golang : rune literal not terminated error
+5.3k Golang : Generate Interleaved 2 inch by 5 inch barcode
+18.4k Golang : Logging with logrus
+15.9k Golang : Update database with GORM example
+11.1k Golang : Simple image viewer with Go-GTK
+8.3k Golang: Prevent over writing file with md5 hash
+6k Golang : Function as an argument type example
+8.8k Golang : Random integer with rand.Seed() within a given range
+13.6k Golang : Qt progress dialog example
+14.2k Golang : Convert IP version 6 address to integer or decimal number
+5.2k Golang : Print instead of building pyramids