title: Can a Jinja variable's scope extend beyond in an inner block?
body: <p>I have the following Jinja template: </p>
  
  <pre><code>{% set mybool = False %}
  {% for thing in things %}
      &lt;div class='indent1'&gt;
          &lt;ul&gt;
              {% if current_user %}
                {% if current_user.username == thing['created_by']['username'] %}
                  {% set mybool = True %}
                  &lt;li&gt;mybool: {{ mybool }}&lt;/li&gt; &lt;!-- prints True --&gt;
                  &lt;li&gt;&lt;a href='#'&gt;Edit&lt;/a&gt;&lt;/li&gt;
                {% endif %}
              {% endif %}
              &lt;li&gt;Flag&lt;/li&gt;
          &lt;/ul&gt;
      &lt;/div&gt;
      &lt;hr /&gt;
  {% endfor %}
  
  {% if not mybool %}
      &lt;!-- always prints this --&gt;
      &lt;p&gt;mybool is false!&lt;/p&gt;
  {% else %}
    &lt;p&gt;mybool is true!&lt;/p&gt;
  {% endif %}
  </code></pre>
  
  <p>If the condition is met in the <code>for</code> loop, I'd like to change <code>mybool</code> to true so I can display <code>mybool is true!</code> below. However, it looks like the scope of the inner <code>mybool</code> is limited to the <code>if</code> statement, so the <em>desired</em> <code>mybool</code> is never set. </p>
  
  <p>How can I set the "global" <code>mybool</code> so I can use it in the last <code>if</code> statement? </p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I've found <a href="http://webcache.googleusercontent.com/search?q=cache:BCRT8FHONykJ:svn.python.org/projects/external/Jinja-1.2/docs/html/scopes.html+jinja+top+level+variable&amp;hl=en&amp;gl=us&amp;strip=0">some suggestions</a> (only the cached page views correctly), but they don't seem to work. Perhaps they're deprecated in Jinja2...</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Solution provided below. I am still curious why the suggestions above do not work though. Does anyone know for sure that they were deprecated? </p>