Hi, In the earlier lecture we discussed about how to include a template within another template.
Also, I mentioned about two ways of including the template.
One is using the keyword template, another one using include. In the earlier example we saw using the keyword
template. While discussing that, I mentioned an important point
while including the template, the alignment doesn't matter.
And within the template, whatever the alignment provided that will be taken as it is.
Now, let me get into the template where I have defined the details. Here
I have provided the alignments. With the same alignments
It will get included and it's quite difficult to identify or assume where it is going to get included
And at what indentations
See, for example, I might use this particular label in different yaml files and in different yaml files
Different type of indentation might be used.
And having different files for different indentation is going to be a difficult and hard task.
That's where another type of template include methodology is introduced that is using the keyword include.
Now let's do the same demo using the template and how to overcome that using the include keyword.
Let me get into the demo. As a part of the helper
I'm going to introduce another template definition.
I'm providing the name mychart.version, assume I do not have any alignments.
Now I'm going to include this particular template using the keyword template.
So template mychart.version I'm including.
Now, let me go ahead and do a dry run and check how it's working.
Let me run the dry run. It's going to give the passing error.
The reason because it doesn't get indented properly.
I can overcome this particular problem by using include.
Let me go ahead and edit the template file.
here I'm going to use include.
Include provides additional option of mentioning how much indentation I wanted for this particular template.
In this particular template, I included the lines for the labels and that needs to come after four spaces.
So indent I will mention four that will be done using the pipeline and here
I'm going to mention the keyword include and name of the template to include and dot to pass the current scope.
Then pipe and how much amount of indent I wanted. For even better understanding
Let me go ahead and include the same thing over here along with the data.
In case if I wanted that to get listed along with the data, then the indent should be of two spaces.
Here I can mention same thing with indent as two. Now for better understanding
lets see the content within the template definition. Here
I do have two lines appname and appversion.
And when it is getting included as a part of the labels, the indent will be four spaces along with the data.
The indent will be two spaces. Let me go ahead and do a dry run.
yes, It's generated properly here the appname and appversion got included with four space because label
demands four spaces and along with the data, it got included with two spaces and always it is recommended
to use include because it will have more control as well as it facilitates the reusability.
This is for the reusability when I mean, in some places I may wanted that with four indent.
And in some places I may wanted that with two indent.
So as per the requirement I can configure
But if I use the template that's going to be a difficult task.
In a quick summary we have seen the different type of keywords to use to include the templates that
is include and template keyword and what are all the differences
And which one is better and how include keyword is much better than template
keyword while including the templates.