Hi, Let us understand about looping. Like every other language, go template language also provides looping
using range and the syntax is very similar to the other languages where
I will be providing the values of collection to the range and within the block
I can iterate over each and every element and pick the required values and do what
ever the pipeline operation I wanted.
I can do it within the block and the syntax is very simple.
Let's go ahead and do a small demo and get better understanding.
Let me go ahead and add a collection of values as a part of the values file.
We get into the mychart within that I'm going to edit the values file.
Here I'm going to add a key language used
And within that I'm going to provide a collection of values.
Now I'm going to read this specific key and a collection of values and iterate within the template
Let me get into the template, edit the template, within the template
I'm going to get the values.
Let me delete the other lines so that we don't need to worry about the other information. As a part of the data
I'm going to add the language used. So I will provide language used as a key, and within that I wanted to have
a collection of values and here I do have the range and each and every element will be printed.
So what I'm going to do, I'm going to get the lang used and their values.
So I'll be getting collection of values and it will iterate depending on the number of elements within
it. For each and every element
I am going to get the current element, that is the scope within this particular block, and I'm going
to convert that into a title format that is the first capital letter and put within the quote.
So this is a very simple pipeline where I would convert that into a title and quote within it.
And the block is getting over. We save the file and do a dry run.
with this particular chart resources helm install dry run and provide the name of the release
and the chart resources. Here
It read the collection of values and it converted the first letter in to capital letter and put within
the quote. So the main thing that we need to worry about is it read the collection of values
And iterated depending on the number of elements within it and printed them as a part of the template.
And this particular range, we can use it by other means as well, where I can read the individual element
and assign it to a variable and access the variable within the block, that we will be seeing it as a
part of the variable section.
So in a quick summary we learnt about how to iterate over the collection using the range.