Hi,
I have an array of maps that I pass into a golang template. How can extract a value from a map at a given index. This is kinda what I want :
{{index {{index .Amap 123}} "akey"}}
Is there any way to do such a thing?
Thanks
Andy
Hi,
I have an array of maps that I pass into a golang template. How can extract a value from a map at a given index. This is kinda what I want :
{{index {{index .Amap 123}} "akey"}}
Is there any way to do such a thing?
Thanks
Andy
This should work:
{{index (index .Amap 123) "key"}}
Absolutely brilliant… how come I couldnt find out how to do that…
Don’t know. It is the last item from https://golang.org/pkg/text/template/#hdr-Arguments
The templating stuff is its own little language. It’s hard to put the parts into context until you need them.
The docs have a difficult job to do because they both have to teach the language and provide the reference for it.
Maybe after I finish my Guide to JSON I will tackle the template packages.
Looking forward to this guide to JSON being available
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.