20.24. kb-00023: Nested Templates (or “Sub-templates”)¶
Knowledge Base Article: kb-00023
20.24.1. Description¶
Understanding how to use templates nested inside of other templates (eg “sub-templates).
20.24.2. Solution¶
The Golang templating language does not provide a call-out to include another template. However, at RackN, we’ve added the ability to include nested templates (sometimes referred to as sub-templates). In any content piece that is valid to use the templating capabilities, simply use the following Template construct to refer to another template. The template referred to will be expanded inline in the calling template.
The nested template example below calls the template named (oddly enough) nested.tmpl.
{{template "nested.tmpl" .}} # or alternatively: {{$templateName := (printf "part-seed-%s.tmpl" (.Param "part-scheme")) -}} {{.CallTemplate $templateName .}}
The template
construct is a text string that refers to a given template name which exists already.
The CallTemplate
construct can be a variable or expression that evaluates to a string.
20.24.3. Additional Information¶
Additional resources and information related to this Knowledge Base article.
20.24.3.1. See Also¶
20.24.3.2. Versions¶
v4.0 and newer
20.24.3.3. Keywords¶
templates, sub-templates, nested templates, workflow
20.24.3.4. Revision Information¶
KB Article : kb-00023 initial release: Wed Jun 10 11:56:49 PDT 2020 updated release: Wed Jun 10 11:56:49 PDT 2020