Standard library / text/template
text/template.ParseFS()
Parses matching files from an fs.FS; here an in-memory filesystem. Expected stdout: 'Hello Ada\n'.
Formal Syntax & Structure
go syntaxgo
func ParseFS(fsys fs.FS, patterns ...string) (*Template, error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| fsys | fs.FS | Filesystem containing template files. |
| patterns | ...string | File glob patterns to match. |
Return Value
(*Template, error)
Parses matching files from an fs.
Working Example
Example Snippetgo
package main
import ( "fmt" "os" "testing/fstest" "text/template")
func check(e error) { if e != nil { panic(e) }}
func main() { fsys := fstest.MapFS{"greet.tmpl": {Data: []byte("Hello {{.}}")}} t, e := template.ParseFS(fsys, "*.tmpl") check(e) check(t.Execute(os.Stdout, "Ada")) fmt.Println()}