add defaultIfEmpty function for template default values
This commit is contained in:
parent
5183e62271
commit
8da9de3177
@ -56,10 +56,19 @@ func (re *Render) apply(opts ...RenderOptions) *Render {
|
||||
return re
|
||||
}
|
||||
|
||||
func defaultIfEmpty(fallback, value string) string {
|
||||
if strings.TrimSpace(value) == "" {
|
||||
return fallback
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func (re *Render) Template(w http.ResponseWriter, tmpl string, td *TemplateData) error {
|
||||
var tc templateCache
|
||||
var err error
|
||||
|
||||
re.Functions["default"] = defaultIfEmpty
|
||||
|
||||
if td == nil {
|
||||
td = &TemplateData{}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user