The Templater Module¶
-
class
smacha.templater.
Templater
(template_dirs=[], include_comments=False, include_introspection_server=False)[source]¶ Main SMACHA template processor class.
The templater uses Jinja2 as its main engine for processing templates, but it also provides some additional features and functionality.
-
find_template_name
(regex, template_env=None)[source]¶ Find a template name in the available template list using a regular expression.
Parameters: - regex (str) – A regular expression used to search the list of templates.
- template_env (
jinja2.environment
) – Optionally specify the template environment. Defaults to current template_env member object.
Returns: The first template name found or an empty string if no template is found.
Return type:
-
get_template_blocks
(template_name)[source]¶ Get all template blocks.
Get a list of all blocks in a given template, either those defined directly in the template itself, or those defined in templates referenced via {% include %} or {% extends %} tags.
Parameters: template_name (str) – The name of the template. Returns: The names of the template blocks. Return type: set of str
-
get_template_refs
(template_name)[source]¶ Get all templates referenced in a template.
Get a list of all templates referenced via {% include %} or {% extends %} tags in a given template.
Parameters: template_name (str) – The name of the template. Returns: The names of the templates referenced by the template. Return type: list of str
-
get_template_vars
(template_name, context=None)[source]¶ Get all variables defined in a template.
Parameters: Returns: The variables defined in the template.
Return type:
-
list_templates
()[source]¶ List the available templates.
Returns: A list of names of templates. Return type: list of str
-
render
(template_name, template_vars)[source]¶ Render code template.
Parameters: Returns: The rendered template code.
Return type:
-
render_all_blocks
(template_name, template_vars)[source]¶ Render all blocks from code template.
Parameters: Returns: The rendered code for each template block.
Return type:
-