Switch or if/elseif/else inside golang HTML templates
Yes, you can use {{else if .IsMenu}}
Yes, you can use {{else if .IsMenu}}
Use the function not: {{ if not .loggedIn }} <h1>Not logged in</h1> {{ end }}
Yes it is possible. A html.Template is actually a set of template files. If you execute a defined block in this set, it has access to all the other blocks defined in this set. If you create a map of such template sets on your own, you have basically the same flexibility that Jinja / … Read more
You use the index function: {{index .Amap “key1”}} index Returns the result of indexing its first argument by the following arguments. Thus “index x 1 2 3” is, in Go syntax, x[1][2][3]. Each indexed item must be a map, slice, or array. https://golang.org/pkg/text/template#hdr-Functions
Check the Variables section in the Go template docs. A range may declare two variables, separated by a comma. The following should work: {{ range $key, $value := . }} <li><strong>{{ $key }}</strong>: {{ $value }}</li> {{ end }}