wp-go/internal/theme/templateFuncs.go

32 lines
567 B
Go
Raw Permalink Normal View History

package theme
2023-01-17 15:18:31 +00:00
import (
"github.com/fthvgb1/wp-go/internal/wpconfig"
2023-01-17 15:18:31 +00:00
"html/template"
"time"
)
2023-01-21 06:49:24 +00:00
var comFn = template.FuncMap{
2023-01-17 15:18:31 +00:00
"unescaped": func(s string) any {
return template.HTML(s)
},
"dateCh": func(t time.Time) any {
return t.Format("2006年 01月 02日")
},
"getOption": func(k string) string {
return wpconfig.GetOption(k)
2023-01-17 15:18:31 +00:00
},
2023-01-19 06:12:59 +00:00
"getLang": wpconfig.GetLang,
2023-01-17 15:18:31 +00:00
}
func FuncMap() template.FuncMap {
2023-01-21 06:49:24 +00:00
return comFn
2023-01-17 15:18:31 +00:00
}
2023-01-26 17:03:41 +00:00
func addTemplateFunc(fnName string, fn any) {
2023-01-21 06:49:24 +00:00
if _, ok := comFn[fnName]; ok {
panic("exists same name func")
2023-01-17 15:18:31 +00:00
}
2023-01-21 06:49:24 +00:00
comFn[fnName] = fn
2023-01-17 15:18:31 +00:00
}