Hi, Now let us understand how to have the template as a part of a separate file and include in another template.
Let me get into the project. As a part of templates
I'm going to create a file.
With prefix underscore, all the helper files will be having the prefix underscore
So I'm going to create a file.
with the name underscore helpers.tpl. As a part of this I'm going to include the template
content that we had as a part of the main file.
So it's going to have a name, mychart.system labels.
And the alignment within the template is important than how we are going to include within the main file.
Let me go ahead and edit the main file.
This particular content is not required as it is already included within the main file.
And I'm going to include the template with the name mychart.system labels.
It also proves the name of the template is universal.
In case if I have any template with duplicate names, the one that is getting loaded latest will
be used. So always it is recommended to follow the name space structure and avoid duplicates of the template file names.
So what we have done, we created another file underscore helpers.tpl and included the template content within it.
And the same template is referred within this particular file config map.yaml file.
As we discussed earlier, the template folders can have three type of files.
One is the yaml files, which are going to have manifest for kubernetes and notes.txt file which will
have information about this particular charts and the resources.
We will have a detailed discussion about the notes files
And helpers file will have all the helpers template which will get included in the main template.
Now, let me go ahead and do a dry run.
So the labels were included as a part of the main template.
This is another way of including the template.
And this is what is recommended where
I can have the atomic content of different templates in the helper template file and include in the
main template files. Now let us understand
What if we include the built-In global objects as a part of the templates and how the scope will
get transferred into the templates.
Now I'm going to edit the same template file.
And as a part of the labels, I am going to include few builtin objects. So I'm including the builtin
objects like release.name, chart.appversion, release.service
So it should pick this particular global builtin objects and print it over here.
That's going to be a surprise where the values will be blank.
Let's go ahead and do a dry run of this particular chart.
I'm not having any value for the builtin objects.
The reason, because the templates where I'm going to use I need to pass the context so that that
can be used as a scope and that can be passed as a dot or dollar.
Lets try out both the options. Let me edit the template, so when the template is getting invoked
I need to pass the scope as well that can be passed as a dot.
That means the current templates scope will get passed to this particular template
And this particular template will have the builtin objects so that it can pass and the values would
get printed. Let me do the dry run.
Yes, it's able to get the values. Instead of dot I can use the dollar as well.
Dollar is what more recommended.
Let's try out that particular option as well.
So while invoking the template instead of dot I can use the
dollar as well. Now, let me go ahead and do the dry run.
Now also I'm able to get the global builtin objects.
So that means whenever I'm going to use the named templates
I need to pass the scope if I have to use any of the global builtin objects.