March 2019
Intermediate to advanced
412 pages
9h 49m
English
This variable is only defined if the macro itself accesses the kwargs variable to catch any extra keyword arguments that might have been passed along. Without accessing the kwargs variable, any extra keyword arguments in a call to the macro will result in an error when rendering the template. Likewise, accessing catch_kwargs without also accessing kwargs will result in an undefined error. Let's modify our example template again so that we can pass along extra kwargs:
{% macro test() -%}
{{ kwargs }}
{{ test.catch_kwargs }}
{%- endmacro -%}
{{ test(unexpected='surprise') }}
The rendered version of this template will be as follows:
As we can see from this output, the template does not error when an unexpected variable is passed ...
Read now
Unlock full access