Template Files¶
Template files are registered in .slcc or .slcp files using the template_file
key. Upon project generation, the template file is rendered to the autogen/
directory in the project using the Jinja2 templating engine. If the template file name has a .jinja
or .jinja2
extension, it is stripped.
Components and projects may register variables for use in the Jinja2 template file. All components present in the project contribute variables to the same global pool, which is available to all templates for the given project generation. This is done using the template_contribution
key. Variables registered using template contributions are always lists, where each template contribution entry adds one element to the list. If multiple components provide content to the same variable, the list is ordered by the priority
given to each contribution from lowest to highest (most negative to most positive). When two contributions have the same priority, the id
of the contributing component is used to achieve stable sorting.
Built-in Functionality¶
In addition to the contributions from components, some macros are made available to templates by the templating engine itself:
autogenerated_file
- emits a description that the file is generated and what template it was generated from. Takesprefix
andsuffix
arguments that are added to each line of the output, suitable for wrapping the description in comment tags for the target language of the generated file.autogenerated_c_file
- equivalent to{{ autogenerated_file | format(prefix='// ', suffix='')}}
Example¶
Component:
1 2 3 4 5 6 7 8 |
|
Template:
1 2 3 4 5 6 7 8 9 |
|
Output:
1 2 3 4 5 6 7 8 |
|