Import / include assigned variables in Jinja2
        Posted  
        
            by Brian M. Hunt
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Brian M. Hunt
        
        
        
        Published on 2010-06-10T19:10:19Z
        Indexed on 
            2010/06/10
            19:13 UTC
        
        
        Read the original article
        Hit count: 410
        
In Jinja2, how can one access assigned variables (i.e. {% set X=Y %}) within files incorporated with include?
I'd expect the following to work given two Jinja2 files:
A.jinja:
Stuff
{% include 'B.jinja' -%}
B has {{ N }} references
B.jinja:
{% set N = 12 %}
I'd expect that A.jinja, when compiled with Jinja2, would produce the following output:
Stuff 
B has 12 references
However, it produces:
Stuff
B has  references
I'd be much obliged for any input as to how to access the Jinja2 variables, such as N above, in the file that includes the file where N is set.
Thank you for reading.
Brian
© Stack Overflow or respective owner