You could write a view to build and represent a select
element:
{{define "select"}}
<select name="{{.Name}}>
{{range $a, $b := .Options}}
<option value="{{print $a}}" {{if $a == .Selected}}>{{print $b}}</option>
{{end}}
</select>
{{end}}
And the corresponding data structure:
type SelectBlock struct {
Name string
Selected string
Options map[string]string
}
Then instantiate it:
termSelect := SelectBlock{
Name: "term",
Selected: "",
Options: map[string]string{
"full-time": "Full Time",
"part-time": "Part Time",
"contract": "Contract",
"freelance": "Freelance",
},
}
And set the Selected
field:
termSelect.Selected = "full-time"
And output the view fragment inside your form view:
{{template "select" $termSelect}}
Where $termSelect
would be your instance of SelectBlock
.