如何在GO中使用间接模板函数链接多个条件?
我想判断.hello
是否不包含"world",.world
是否不包含"Hello",但我不能,因为我收到了2009/11/10 23:00:00 executing template: template: content:2:5: executing "content" at <not>: wrong number of args for not: want 1 got 2
错误消息
package main
import (
"log"
"os"
"strings"
"text/template"
)
var (
templateFuncMap = template.FuncMap{
"contains": strings.Contains,
}
)
func main() {
// Define a template.
const temp = `
{{if not (contains .hello "hello") (contains .world "hello") }}
passed
{{else}}
not passed
{{end}}`
s := map[string]string{
"hello": "world",
"world": "hello",
}
t := template.Must(template.New("content").Funcs(templateFuncMap).Parse(temp))
err := t.Execute(os.Stdout, s)
if err != nil {
log.Println("executing template:", err)
}
}