Partials take styling class for section as param

This commit is contained in:
2025-09-05 11:39:14 +02:00
parent 13fe19abda
commit 3e4a4636fa
5 changed files with 30 additions and 7 deletions

20
main.go
View File

@ -98,8 +98,26 @@ func NewServer() *Server {
SonBirthDate: getEnv("SON_BIRTH_DATE", "2022-01-01"),
}
// Template Funcs
funcs := template.FuncMap{
"dict": func(values ...interface{}) (map[string]interface{}, error) {
if len(values)%2 != 0 {
return nil, fmt.Errorf("dict expects even number of args")
}
m := make(map[string]interface{}, len(values)/2)
for i := 0; i < len(values); i += 2 {
k, ok := values[i].(string)
if !ok {
return nil, fmt.Errorf("dict keys must be strings")
}
m[k] = values[i+1]
}
return m, nil
},
}
// Parse templates with error handling
templates, err := template.ParseGlob("templates/*.html")
templates, err := template.New("").Funcs(funcs).ParseGlob("templates/*.html")
if err != nil {
log.Fatalf("Failed to parse templates: %v", err)
}