I am trying to compare the length of a list in golang html/template. But it is loading forever in html.
{{ $length := len .SearchData }} {{ if eq $length "0" }}
Sorry. No matching results found
{{ end }}
Could anyone help me with this?
I am trying to compare the length of a list in golang html/template. But it is loading forever in html.
{{ $length := len .SearchData }} {{ if eq $length "0" }}
Sorry. No matching results found
{{ end }}
Could anyone help me with this?
A shorter version
From documentation,
So if you want to check if the
.SearchData
slice/array/map is empty just use,Even your code runs fine if string
"0"
is replaced by int0
http://play.golang.org/p/Q44qyRbKRB
There is
{{ else }}
for{{ range }}
Works well for maps as well https://play.golang.org/p/7xJ1LXL2u09: