get_template_attribute
Loads a macro (or variable) a template exports. This can be used to invoke a macro from within Python code. If you for example have a template named :file:_cider.html with the following contents:
.. sourcecode:: html+jinja
{% macro hello(name) %}Hello {{ name }}!{% endmacro %}
You can access this from Python code like this::
hello = get_template_attribute('_cider.html', 'hello')
return hello('World')
def get_template_attribute(
template_name: str,
attribute: str
) - > t.Any
Loads a macro (or variable) a template exports. This can be used to invoke a macro from within Python code.
Parameters
| Name | Type | Description |
|---|---|---|
| template_name | str | The path or identifier of the Jinja template to load |
| attribute | str | The name of the specific macro or variable exported by the template to retrieve |
Returns
| Type | Description |
|---|---|
t.Any | The exported macro or variable from the template's module namespace |