Standard library / html/template

html/template.ParseFiles()

Parses named files; the first file basename names the returned template. Expected stdout: 'Hello Ada\n'.

Formal Syntax & Structure

go syntaxgo
func ParseFiles(filenames ...string) (*Template, error)

Parameters & Attributes

NameTypeDescription
filenames...stringPaths of template files to parse.

Return Value

(*Template, error)

Parses named files; the first file basename names the returned template.

Working Example

Example Snippetgo
package main
import (  "fmt"  "html/template"  "os"  "path/filepath")
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.ParseFiles(path)  check(e)  check(t.Execute(os.Stdout, "Ada"))  fmt.Println()}
Go Reference