100

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] }}
Glstunna
  • 1,993
  • 3
  • 18
  • 27

2 Answers2

163

You need to use the index template function.

{{index .a 2}}
Ken Bloom
  • 57,498
  • 14
  • 111
  • 168
21

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 .

User12547645
  • 6,955
  • 3
  • 38
  • 69
Sandeep Jain
  • 1,019
  • 9
  • 13