There is no equality statement in the base template package.
Here is an interesting discussion from golang-nuts about it.
You have several possibilities:
if conditionselected boolean field and give an array of 6 of these objects to a template with a range statementI recreated your example by using a slice of booleans:
func main() {
temp,err := template.ParseFiles("template.html")
if err != nil {
panic(err)
}
g := make([]bool, 7)
g[1] = true
temp.Execute(os.Stdout, &g)
}
A line in the template looks like this:
<option value="3"{{ if index . 3 }} selected="selected"{{ end }}>Grade Three</option>
This doesn't look so good to me. But I'd say that all solutions have their drawbacks and that this is a matter of taste (the third solution should be cleaner but might be considered overkill for such a simple thing).
Edit (2013/12/11)
In Go 1.2 (released on 2013/12/01), the template engine has been updated and includes new operators, including comparison. This now should work as expected:
{{if eq .Grade 1 }} selected="selected" {{end}}
You can still choose to keep as few logic as possible in your templates, though.