Standard library / html/template

html/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(fs fs.FS, patterns ...string) (*Template, error)

Parameters & Attributes

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

Return Value

(*Template, error)

Parses matching files from an fs.

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