Jinja Macro Attributes
n
n
In addition to their functionality, Jinja2 macros expose several attributes that provide information about their internal details. These attributes can be useful for introspection and debugging, allowing you to check a macro’s properties programmatically.
nn
n
Available Attributes
n
- n
name: Returns the name of the macro as a string.n{% macro say_hello(name) %}n Hello, {{ name }}!n{% endmacro %}nn<p>The macro's name is: {{ say_hello.name }}</p>n
arguments: A tuple of the names of the arguments the macro accepts.n{% macro my_macro(a, b, c) %}n ...n{% endmacro %}nn<p>Arguments: {{ my_macro.arguments|join(', ') }}</p>n
catch_kwargs: `True` if the macro accepts extra keyword arguments (via thekwargsvariable).catch_varargs: `True` if the macro accepts extra positional arguments (via thevarargsvariable).caller: `True` if the macro uses thecallervariable and can be called from a{% call %}tag.
n
n
n
n
n
n
{% macro my_flexible_macro(name, *varargs, **kwargs) %}n ...n{% endmacro %}nn<p>Accepts `kwargs`: {{ my_flexible_macro.catch_kwargs }}</p>n<p>Accepts `varargs`: {{ my_flexible_macro.catch_varargs }}</p>n<p>Accepts `caller`: {{ my_flexible_macro.caller }}</p>
n
nn
n
Private Macros
n
If a macro’s name starts with an underscore (_), it is considered private. This means it can only be used within the template where it is defined and cannot be imported by other templates.
nn
n
n
