How are extra args & kwargs handled for a Jinja2 macro? The documentation isn\'t exactly clear offhand.
For example, this is clearly wrong:
{% macr
The trick is that kwargs
has to be accessed at least once in any macro that should accept them. That is to say, you must call {{ kwargs }}
once in macro body without declaring it in macro argument list. The same is true for {{ varargs }}
.
This will not work
{% macro example_2(one, two) %}
* {{one}} - {{two}}
{% endmacro %}
{{example_2(1, 2, test="Hello")}}
This will
{% macro example_2(one, two) %}
* {{one}} - {{two}}
* {{kwargs}}
{% endmacro %}
{{example_2(1, 2, test="Hello")}}