Skip to content Skip to sidebar Skip to footer

Jinja2 Macro Import "with Context" And Global Variables: {% From File.html Import Macro_name With Context %}

In Jinja2 template engine for python, my macro 'with context' could not access the global variables from the context. Import statements: {% import 'en-US/my_macro.html' as all_mac

Solution 1:

The issue arises because there are 2 ways to call the macro. One is from the all_macros import. The second is with the name the_macro.

If I use the call:

{{ the_macro() }}

Then the macros have access to the global variables from the context! This is really a clarification of the documentation.

Post a Comment for "Jinja2 Macro Import "with Context" And Global Variables: {% From File.html Import Macro_name With Context %}"