I have the following Jinja template:
{% set mybool = False %} {% for thing in things %} <div class='indent1'> <ul> {% if current_user %} {% if current_user.username == thing['created_by']['username'] %} {% set mybool = True %} <li>mybool: {{ mybool }}</li> <li><a href='#'>Edit</a></li> {% endif %} {% endif %} <li>Flag</li> </ul> </div> <hr /> {% endfor %} {% if not mybool %} <p>mybool is false!</p> {% else %} <p>mybool is true!</p> {% endif %}
If the condition is met in a for loop, I would like to change mybool to true so that I can display mybool is true! below. However, it seems that the scope of the internal mybool limited by the if , so the desired mybool never installed.
How can I set the "global" mybool so that I can use it in the last if ?
EDIT
I found some suggestions (only cached pages were viewed correctly), but they don't seem to work. Perhaps they are deprecated in Jinja2 ...
EDIT
The solution is given below. I'm still wondering why the above suggestions do not work. Does anyone know for sure that they are out of date?
variables scope templates jinja2
Matt Norris Feb 02 2018-11-02T00: 00Z
source share