I have a for loop in a jinja template:
<ul>
{%- for t in tree recursive %}
<li><span class="li_wrap">
<span><i class="glyphicon {{ 'glyphicon-folder-close' if t.type == 'folder' else 'glyphicon-file'}}"></i> {{ t.name }}</span>
{% if t.type != 'folder' %}
<span class="pull-right">Size: {{ t.size/1000 }} kb </span>
{% endif %}
</span>
{%- if t.children -%}
<ul>{{ loop(t.children) }}</ul>
{%- endif %}
</li>
{%- endfor %}
</ul>
what I want is to sum the value of t.size
and use it as a total size number, but above this block.
What is the best way to do that?
You must use the jinja function SUM => http://jinja.pocoo.org/docs/
This code should work
Total: {{ t|sum(attribute='size') }}
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