You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What steps will reproduce the problem?
1. go run
package main
import (
"fmt"
"os"
"strings"
"text/template"
)
func T(s string) string {
return strings.Replace(s, "o", "a", -1)
}
type S struct {
Filter func(string) string
Name string
}
const tpl = `{{ .Filter .Name }}`
var t = template.Must(template.New("t").Parse(tpl))
func main() {
s := S{Filter: T, Name: "toto"}
err := t.Execute(os.Stdout, s)
if err != nil {
fmt.Println(err)
}
}
What is the expected output? What do you see instead?
Expected:
tata
Got:
template: t:1:3: executing "t" at <.Filter>: Filter has arguments but
cannot be invoked as function
go version devel +ea15e7ed6d72 Sun Dec 09 03:59:33 2012 -0500
The text was updated successfully, but these errors were encountered:
The original intention was to make Filter a named type with a Name method in order to
study the difference between {{ .Filter.Name }} and {{ .Filter .Name }}
Oh, I'm stupid, the documentation says a function call can only be with a method or a
function from the FuncMap, and .Filter is neither of these, "call .Filter .Name" is the
correct syntax. Maybe the error message could be more useful.
The text was updated successfully, but these errors were encountered: