Path 1: 1 calls (1.0)

'_macro.html' (1)

'hello' (1)

Macro (1)

1def get_template_attribute(template_name: str, attribute: str) -> t.Any:
2    """Loads a macro (or variable) a template exports.  This can be used to
3    invoke a macro from within Python code.  If you for example have a
4    template named :file:`_cider.html` with the following contents:
5
6    .. sourcecode:: html+jinja
7
8       {% macro hello(name) %}Hello {{ name }}!{% endmacro %}
9
10    You can access this from Python code like this::
11
12        hello = get_template_attribute('_cider.html', 'hello')
13        return hello('World')
14
15    .. versionadded:: 0.2
16
17    :param template_name: the name of the template
18    :param attribute: the name of the variable of macro to access
19    """
20    return getattr(current_app.jinja_env.get_template(template_name).module, attribute)