HiveBrain v1.2.0
Get Started
← Back to all entries
snippetgoModerate

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

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
arraytemplateshowaccessarritem

Problem

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 .

Code Snippets

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

Context

Stack Overflow Q#31235211, score: 32

Revisions (0)

No revisions yet.