Repository: gohugoio/hugo (language: go)

Issue:
Cannot use namespaced function in the apply function
```text
{{ $a := apply $b "strings.Trim" "." " " }}
```

> error calling apply: can't find function strings.Trim

But this works:

```text
{{ $a := apply $b "trim" "." " " }}
```

But many of the functions don't have aliases. For example: `strings.TrimLeft`


Discussion / hints:
@moorereason I know it's been a while, but you know this code pretty well. If you have a moment...

Fix patch:
diff --git a/tpl/collections/apply.go b/tpl/collections/apply.go
index 86554def1c1..6eedb4b6351 100644
--- a/tpl/collections/apply.go
+++ b/tpl/collections/apply.go
@@ -111,15 +111,25 @@ func (ns *Namespace) lookupFunc(fname string) (reflect.Value, bool) {
 
 	ss := strings.SplitN(fname, ".", 2)
 
-	// namespace
+	// Namespace
 	nv, found := ns.lookupFunc(ss[0])
 	if !found {
 		return reflect.Value{}, false
 	}
 
+	fn, ok := nv.Interface().(func(...interface{}) (interface{}, error))
+	if !ok {
+		return reflect.Value{}, false
+	}
+	v, err := fn()
+	if err != nil {
+		panic(err)
+	}
+	nv = reflect.ValueOf(v)
+
 	// method
 	m := nv.MethodByName(ss[1])
-	// if reflect.DeepEqual(m, reflect.Value{}) {
+
 	if m.Kind() == reflect.Invalid {
 		return reflect.Value{}, false
 	}


Test patch:
diff --git a/hugolib/template_test.go b/hugolib/template_test.go
index 2908fdf71a1..f9d54d8dc04 100644
--- a/hugolib/template_test.go
+++ b/hugolib/template_test.go
@@ -460,7 +460,6 @@ complex: 80: 80
 
 // Issue 7528
 func TestPartialWithZeroedArgs(t *testing.T) {
-
 	b := newTestSitesBuilder(t)
 	b.WithTemplatesAdded("index.html",
 		` 
@@ -483,7 +482,6 @@ X123X
 X123X
 X123X
 `)
-
 }
 
 func TestPartialCached(t *testing.T) {
@@ -757,3 +755,20 @@ This is single main
 `,
 	)
 }
+
+// Issue 9393.
+func TestApplyWithNamespace(t *testing.T) {
+	b := newTestSitesBuilder(t)
+
+	b.WithTemplates(
+		"index.html", `
+{{ $b := slice " a " "     b "   "       c" }}		
+{{ $a := apply $b "strings.Trim" "." " " }}
+a: {{ $a }}
+`,
+	).WithContent("p1.md", "")
+
+	b.Build(BuildCfg{})
+
+	b.AssertFileContent("public/index.html", `a: [a b c]`)
+}