I have "FormError" struct. I pass this struct to my template. So how to access InputError struct field value with specific key in the template?
type InputError struct {
Val string
Has bool
}
type FormError struct {
Errs map[string]InputError
}
This doesn't work.
<input name="Name" type="text" value="{{index .Errs.Val `Name`}}">
Use {{.Errs.Name.Val}}
. There's no need to use index.
Errs.Val
isn't valid, you need to separate the lookup and field access:
{{ $myval := index .Errs "key" }} {{ $myval.Val }}
Or if you only need to use the value once:
{{ (index .Errs "key").Val }}