A similar question was answered here , but I do not think it solves my problem.
Let's say you have the following structure:
type User struct { Username string Password []byte Email string ... }
In addition, the URL has the following structure: example.com/en/users, where "en" is the URL parameter that will be passed to the template as follows:
renderer.HTML(w, http.StatusOK, "users/index", map[string]interface{}{ "lang": chi.URLParam(r, "lang"), "users": users})
And in the HTML template, I have the following:
{{ range .users }} <form action="/{{ .lang }}/users" method="POST"> <input type="text" name="Username" value="{{ .Username }}"> <input type="text" name="Email" value="{{ .Email }}"> </form> {{ end }}
Now the problem is that since {{.lang}} is not part of the User structure, I get an error .. since I can access the {{.lang}} inside {{range.users}}
source share