mirror of
https://github.com/ducky-labs/htmx-go-todo.git
synced 2026-02-04 06:31:00 +00:00
Changes
This commit is contained in:
35
tmpl.go
Normal file
35
tmpl.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/Masterminds/sprig/v3"
|
||||
)
|
||||
|
||||
var tmpl *template.Template
|
||||
|
||||
func parseTemplates() error {
|
||||
t := template.New("").Funcs(sprig.FuncMap())
|
||||
err := filepath.Walk("templates", func(path string, _ fs.FileInfo, err error) error {
|
||||
if strings.Contains(path, ".html") {
|
||||
tmplBytes, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = t.New(path).Funcs(sprig.FuncMap()).Parse(string(tmplBytes))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return err
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tmpl = t
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user