go - How to check non standard object equivalence in golang template -



go - How to check non standard object equivalence in golang template -

i outputting dropdown list using html template, follows:

{{range .organisations}} <option value="{{.uuid}}">{{.name}}</option> {{end}}

i want indicate 1 of items should selected doing eq comparator. potential complication aware of .uuid *gocql.uuid, trying this:

{{range .organisations}} <option value="{{.uuid}}"{{if eq $.contact.organisation .uuid}} selected="selected"{{end}}>{{.name}}</option> {{end}}

but results in next error message:

page:32:36: executing "submit_scholarship" @ : error calling eq: invalid type comparison

any pointers in right direction much appreciated.

eq works on basic types. can add together custom function this. http://play.golang.org/p/rkynlqmela

package main import ( "html/template" "os" ) type s struct { name []byte uuid []byte } func main() { info := s{[]byte("aa"), []byte("aa")} funcmap := template.funcmap{ "equals": func(a []byte, b []byte) bool { homecoming string(a) == string(b) }, } var html = `{{if equals .name .uuid }}hi{{end}}` tmpl, _ := template.new("test").funcs(funcmap).parse(html) err := tmpl.execute(os.stdout, data) if err != nil { println(err.error()) } }

go gocql

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -