Nested {{index ... }} pipelines in golang templates

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"}}
1 Like

Absolutely brilliant… how come I couldnt find out how to do that…

1 Like

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.

2 Likes

Looking forward to this guide to JSON being available :slight_smile:

1 Like

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