Standard library / text/template

text/template.Template.ParseFS()

Parses filesystem patterns into an existing template namespace. Expected stdout: 'Hello Ada\n'.

Formal Syntax & Structure

go syntaxgo
func (t *Template) ParseFS(fsys fs.FS, patterns ...string) (*Template, error)

Parameters & Attributes

NameTypeDescription
fsysfs.FSFilesystem containing template files.
patterns...stringFile glob patterns to match.

Return Value

(*Template, error)

Parses filesystem patterns into an existing template namespace.

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.New("greet.tmpl").ParseFS(fsys, "*.tmpl")  check(e)  check(t.Execute(os.Stdout, "Ada"))  fmt.Println()}
Go Reference