Glstunna
Glstunna

Reputation: 2069

Go templates: How do I access array item (arr[2]) in templates?

How do I access an array item (e.g. a[2]) in templates?

Whenever I do this I get "bad character U+005B '['"

{{ .a[2] }}

Upvotes: 109

Views: 57399

Answers (2)

Sandeep Jain
Sandeep Jain

Reputation: 1262

to access a field on an array item as go templating in *.yaml format :

{{ (index .Values.fields 0).fieldItem }}

Index of zero(0) as in fields array of field as fieldItem .

Upvotes: 29

Ken Bloom
Ken Bloom

Reputation: 58770

You need to use the index template function.

{{index .a 2}}

Upvotes: 173

Related Questions