tpl: Make the *langURL funcs tace interface{}
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 13 Sep 2016 15:07:52 +0000 (17:07 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 13 Sep 2016 15:07:52 +0000 (17:07 +0200)
Fixes #2447

tpl/template_funcs.go

index c82b6fae8ad50350e0e5e97b13e616cefa5c80d4..099f9d74e472140d4122f837362a3393425de92c 100644 (file)
@@ -1907,8 +1907,14 @@ func relURL(a interface{}) (template.HTML, error) {
 
 func init() {
        funcMap = template.FuncMap{
-               "absURL":       absURL,
-               "absLangURL":   func(a string) template.HTML { return template.HTML(helpers.AbsURL(a, true)) },
+               "absURL": absURL,
+               "absLangURL": func(i interface{}) (template.HTML, error) {
+                       s, err := cast.ToStringE(i)
+                       if err != nil {
+                               return "", err
+                       }
+                       return template.HTML(helpers.AbsURL(s, true)), nil
+               },
                "add":          func(a, b interface{}) (interface{}, error) { return helpers.DoArithmetic(a, b, '+') },
                "after":        after,
                "apply":        apply,
@@ -1962,7 +1968,13 @@ func init() {
                "readFile":     readFileFromWorkingDir,
                "ref":          ref,
                "relURL":       relURL,
-               "relLangURL":   func(a string) template.HTML { return template.HTML(helpers.RelURL(a, true)) },
+               "relLangURL": func(i interface{}) (template.HTML, error) {
+                       s, err := cast.ToStringE(i)
+                       if err != nil {
+                               return "", err
+                       }
+                       return template.HTML(helpers.RelURL(s, true)), nil
+               },
                "relref":       relRef,
                "replace":      replace,
                "replaceRE":    replaceRE,