Sum of one checkbox field I have a checkbox field which I want the sum of a certain checkbox:

{% set countPremiere = 1 %}
{% set iterationPremiere = 0 %}
{% set premiereTotal = 0 %}

{% for entry in allEntries %} // the normal loop starts

  {% for premiereItem in entry.kompositonsart %} //the checkbox loop starts
    {%- if premiereItem.value == 'ua' -%} // only return checked value with 'ua'
      {{ countPremiere }}
    {% endif %}
  {%- endfor -%}

  {% set premiereTotal = iterationPremiere +  premiereTotal %}

{% endfor %}

{{ premiereTotal }}


That's basically the same as I did here. This doesn't work however. I suspect it is not working because the way checkboxes are looped. Any ideas?
What you could try is putting the "if statement" as a condition in the for loop like this:

{% for premiereItem in entry.kompositonsart if premiereItem.value == 'ua' %} //the checkbox loop starts
    // only return checked value with 'ua'
    {{ countPremiere }}
{% endfor %}


I'm not really sure what you are asking but if my thoughts are right this should do the trick. This way it wont effect any other regular loop functions like a loop.index if you are going to use it.