wp-go/app/theme/templateFuncs.go

38 lines
848 B
Go
Raw Permalink Normal View History

package theme
2023-01-17 15:18:31 +00:00
import (
2023-05-04 12:37:06 +00:00
"github.com/fthvgb1/wp-go/app/pkg/models"
"github.com/fthvgb1/wp-go/app/wpconfig"
2023-01-17 15:18:31 +00:00
"html/template"
"time"
)
2023-04-15 16:57:50 +00:00
func postsFn(fn func(models.Posts) string, a models.Posts) string {
return fn(a)
2023-01-17 15:18:31 +00:00
}
func FuncMap() template.FuncMap {
2024-01-24 07:13:29 +00:00
return template.FuncMap{
"unescaped": func(s string) any {
return template.HTML(s)
},
"dateCh": func(t time.Time) any {
return t.Format("2006年 01月 02日")
},
"timeFormat": func(t time.Time, format string) any {
return t.Format(format)
},
"getOption": func(k string) string {
return wpconfig.GetOption(k)
},
"getLang": wpconfig.GetLang,
"postsFn": postsFn,
"exec": func(fn func() string) template.HTML {
return template.HTML(fn())
},
"callFuncString": func(fn func(string) string, s string) template.HTML {
return template.HTML(fn(s))
},
2023-01-17 15:18:31 +00:00
}
}