.Map in templates?

the template documentation says:

Map keys to values: (useful in advanced cases, with subtemplates, etc.)
{{.Map “key1” “value1” “key2” “value2”}}

But when I try running that code, it actually outputs map[key1:value1 key2:value2] to the page. If I assign the map {{$foo := .Map "key1" "value1" "key2" "value2"}} that stops the output, but then the values aren’t assigned to the global .Map dict.


{{$foo := .Map "key1" "value1" "key2" "value2"}}
{{.Include "base.html"}}


foo is <b>{{.Map}}</b> 

output is: foo is <b>map[]</b> And I can’t access $foo across templates. Is there any further clarity/examples around what the documentation means when it says “useful in advanced cases, with subtemplates, etc.”?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.