Standard library / html/template
html/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(fs fs.FS, patterns ...string) (*Template, error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| fs | fs.FS | Filesystem containing template files. |
| patterns | ...string | File glob patterns to match. |
Return Value
(*Template, error)
Parses filesystem patterns into an existing template namespace.
Working Example
Example Snippetgo
package main
import ( "fmt" "html/template" "os" "testing/fstest")
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()}