I have this struct :
type Site struct {
Name string
Pages []int
}
I pass an instance of Site
to a template.
If I want to write a list of all pages, I do
{{range .Pages}}
<li><a href="{{.}}">{{.}}</a></li>
{{end}}
Now, what's the simplest way to use the Name
field inside the loop (for example to change the href
to Name/page
) ?
Note that a solution based on the fact that the external object is the global one that was passed to the template would be OK.