just wondering what the deal is with the scope of variables in a tornado template. I have this code in a template, but it fails!
{% set dictionary = {'a' : 1, ... more letters here ... 'z' : 26} %}
{% set sum = 0 %}
{% for y in x %}
{% sum += int(dictionary[y.lower()]) #x is a string, y a char %}
{% end %}
{{ sum }}
But I get:
ParseError: unknown operator: 'sum'
What's going on?
Just use set before the sum +=
{% set dictionary = {'a' : 1, ... more letters here ... 'z' : 26} %}
{% set sum = 0 %}
{% for y in x %}
{% set sum += int(dictionary[y.lower()]) #x is a string, y a char %}
{% end %}
{{ sum }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With