Total sum within loop I have simple loop:

{% for total in thing %}
  {{ total.seatsKids }} {{ total.seatsParents }}
{% endfor %}


This results in a string of numbers eg. 1 3 4. I want the sum of all numbers. So how do I get 7 at the end? I don't understand how to write math operations within loops.
To do math in twig, you will need to use the set tag to do assignments, and the + operator to do addition. When doing math inside a for loop, you will need to keep in mind that


  loops are scoped in Twig; therefore a variable declared inside a for loop is not accessible outside the loop itself.
  If you want to access the variable, just declare it before the loop.


It looks as if you have a collection of things that represent seat counts, and you want to loop over them and calculate the totals. So, something like this:

{# define and intialize our variables outside the loop #}
{% set kidSeatTotal = 0 %}
{% set parentSeatTotal = 0 %}

{# loop over the seatCounts and add them up #}
{% for seatCount in thing %}
  {% set kidSeatTotal = kidSeatTotal + seatCount.seatsKids %}
  {% set parentSeatTotal = parentSeatTotal + seatCount.seatsParents %}
{% endfor %}

{# maybe we want the grand total as well #}
{% set grandSeatTotal = kidSeatTotal + parentSeatTotal %}

{# now we can output them: #}
kid seat total: {{ kidSeatTotal }}
parent seat total: {{ parentSeatTotal }}
grand total: {{ grandSeatTotal }}