Standard library / text/template
text/template.ParseGlob()
Parses files matching a filesystem glob; at least one match is required. Expected stdout: 'Hello Ada\n'.
Formal Syntax & Structure
go syntaxgo
func ParseGlob(pattern string) (*Template, error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| pattern | string | Glob pattern for template file paths. |
Return Value
(*Template, error)
Parses files matching a filesystem glob; at least one match is required.
Working Example
Example Snippetgo
package main
import ( "fmt" "os" "path/filepath" "text/template")
func check(e error) { if e != nil { panic(e) }}
func main() { dir, e := os.MkdirTemp("", "template-demo-") check(e) defer os.RemoveAll(dir) path := filepath.Join(dir, "greet.tmpl") check(os.WriteFile(path, []byte("Hello {{.}}"), 0600)) t, e := template.ParseGlob(filepath.Join(dir, "*.tmpl")) check(e) check(t.Execute(os.Stdout, "Ada")) fmt.Println()}