]> Cypherpunks repositories - gostls13.git/commit
Map support for template.Execute().
authorJames Meneghello <rawrz0r@gmail.com>
Fri, 20 Nov 2009 05:08:05 +0000 (21:08 -0800)
committerRob Pike <r@golang.org>
Fri, 20 Nov 2009 05:08:05 +0000 (21:08 -0800)
commitbfbb31595b1621ed8f725b21863e33d59ca5489c
tree932fa884427aec17b39dc94aaf80ac18c5587862
parentc16f5cd9a6bc74ce5c6b98580c8ffbabb3aca9a1
Map support for template.Execute().

Allows the developer to pass a map either by itself for
evaluation, or inside a struct. Access to data inside
maps is identical to the current system for structs, ie.

-Psuedocode-

mp map[string]string = {
"header" : "A fantastic header!",
"footer" : "A not-so-fantastic footer!",
}
template.Execute(mp)

...can be accessed using {header} and {footer} in
the template. Similarly, for maps inside structs:

type s struct {
mp map[string]string,
}
s1 = new s
s1.mp["header"] = "A fantastic header!";
template.Execute(s1)

...is accessed using {mp.header}. Multi-maps, ie.
map[string](map[string]string) and maps of structs
containing more maps are unsupported, but then, I'm
not even sure if that's supported by the language.

Map elements can be of any type that can be written
by the formatters. Keys should really only be strings.

Fixes #259.

R=r, rsc
https://golang.org/cl/157088
src/pkg/template/template.go
src/pkg/template/template_test.go