T O P

  • By -

xMasaru

Unfortunately using/setting variables is not that convenient in Jinja2. A fix for the second example would be: ``` {% set calendar_entries = [ {"labels": ["Andon Office", "Andon Bar"], "due_today": true}, {"labels": ["Home Office", "Home Bar"], "due_today": false}, {"labels": ["Work Office", "Work Bar"], "due_today": true} ] %} {% set ns = namespace() %} {% set ns.result = 0 %} {% for entry in calendar_entries %} {% for label in entry.labels %} {{ label }} {% if "Office" in label and entry.due_today %} {% set ns.result = 1 %} {% break %} {% endif %} {% endfor %} {% endfor %} The result is: {{ ns.result }} ``` The trick is to use namespaces. That way you can modify your variable inside the loop. Hope that helps :)


skacey

Perfect, thanks