Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Helm template prefixes range index with an underscore

We can access the index by this way :

{{- range $i, $s := (some list) }}
{{$i}}
{{-end }}

output:
0
1
..etc

However when the list is a result of a string split, the index becomes prefixed with an underscore

{{- range $i, $s := (split "X" "aaXbbXcc") }}
{{$i}}
{{-end }}

output:
_0
_1
..etc

why?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The split function returns a dict, whose index members are prefixed with a _ character before. It is useful when you are planning to use dot notation for accessing members and not ideally suited for iteration with range.

For accessing the result as a list of strings with their indices, use splitList. See documentation for more information

{{- range $i, $s := (splitList "X" "aaXbbXcc") }}
{{$i}}
{{- end }}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading