templatesgobeego

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] }}

Solution

  • 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 .