A
A
aloky2017-12-28 16:22:22
Jinja
aloky, 2017-12-28 16:22:22

Summation of variables, how to do it?

{% for item in get_items() %}
{{ item.price }}
{% endfor %}

Values ​​of the type are given:
"254 2515 812 213 995", but you need the sum of these numbers.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
aloky, 2018-01-09
@aloky

This problem was solved in this way:

{{ get_items()|map(attribute="price")|map("int")|sum() }}

S
Sergey Gornostaev, 2017-12-28
@sergey-gornostaev

{{ get_items() | sum(attribute='price') }}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question