I'd like to compare two variables of string type inside a range loop as follows:
<select name="category" id="category">
{{range $c := .cats}}
<option value="{{$c.Title}}" {{ if eq $c.Title .category}}active{{end}}>{{$c.Title}}</option>
{{end}}
</select>
both $c.Title
and category
are strings dispatched by the controller.
However, instead on drop down menue being in the rendered template, I get :
can't evaluate field category in type model.category
$c
is of struct type category:
type Category struct {
ID int `db:"id"`
Title string `db:"title"`
Slug string `db:"slug"`
CreatedAt time.Time `db:"created_at"`
}
When I put directly the string value of category
instead of .category
in the code above, there is no issues.
I'm using gowebapp MVC framework, if it does matter.
How can I fix this?