You can simply write {Title}
.
Whenever a template package encounters an identifier, it tries to find it in the current object and, if it does not find anything, it tries to create the parent element (to the root). @
is there if you do not want to access the current object as a whole, and not one of its attributes.
Since I'm not used to the template package, I created a small example:
type Category struct { Title string Count int } func main() { tmpl, _ := template.Parse(` {.repeated section Categories} <p>{Title} ({Count})</p> {.end} `, nil) categories := []Category{ Category{"Foo", 3}, Category{"Bar", 5}, } tmpl.Execute(os.Stdout, map[string]interface{} { "Categories": categories, }) }
tux21b
source share