Partials take styling class for section as param
This commit is contained in:
20
main.go
20
main.go
@ -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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user