set value command in jinja2 works in some cases and not in some -
the following code displays different values of x in different months. set command of jinja2 works flag,x not total. why?
{% set flag = 1 %} {% set total = 0 %} {% date in dates %} //dates array {% if flag == 1 %} {{x}} {% set flag= 0 %} // have used 1+1 works {% elif "jul" in date %} {% set x = x*3 %} {% if x % 10!=0 %} {% set x = x - x % 10 %} {% set total = total + x %} {% endif %} {% else %} {{x}} {% set total = total + x %} {% endif %} {% endfor %} {{total}}
you have complex computational logic in template: better move logic(or part) data-provider component.
for example, in data-provider component can compute x
every data
, place result data.x
. {{dates|sum(attribute='x')}}
display total value.
Comments
Post a Comment