ParseFS parses template files obtained through an io/fs file system and registers them by base filename. With //go:embed, the files are available in memory instead of being opened on every request. section 11.5.3
Parse embedded templates
Embed only the templates needed by the page, then parse them with a template name and function map: template.New("index").Funcs(funcs).ParseFS(templates, "templates/*.html"). When multiple files are loaded, execute the intended file explicitly with ExecuteTemplate(w, "index.html", data). section 11.5.3
Listing 11.46 index.html: Embedding the contents of a directory
//go:embed templates/*.html #1
var templates embed.FS
...
tpl, err := template.New("index").Funcs(template.FuncMap{
"statusCSSClass": statusCSSClass,
"progress": progress,
}).ParseFS(templates, "templates/*.html") #2
Shows the complete //go:embed declaration and ParseFS call for a directory of HTML templates. section 11.5.3
