How can I execute function in templates that returns no value? Here is example:
func main() {
u, err := url.Parse("http://example.com/test?param1=true¶m2=true")
if err != nil {
log.Fatal(err)
}
m := u.Query()
m.Del("param1") // param1 successful deleted!
u.RawQuery = m.Encode()
fmt.Println(u.RawQuery)
const tmpl = `
{{$m := .Query}}
{{$m.Del "param2"}} <!-- failed to delete param2! -->
{{.RawQuery}}
`
t := template.Must(template.New("").Parse(tmpl))
err = t.Execute(os.Stdout, u)
if err != nil {
log.Println("executing template:", err)
}
}
see this code in play.golang.org
I know that in templates shouldn't be much logic, but ignorance of running function that returns no value seems to me interesting issue.