1

I would like to know, how many values are saved in the table field called "artikelnummer" with the field name "artikel". The section is called "bikes". I tried:

{% set entries = craft.entries.section('bikes') %}

{% for entry in entries %}
  {% for row in entry.artikelnummer %}
    {{ row.artikel|length }}
  {% endfor %}
{% endfor %}

Thanks!

  • {{ row.length }} gives me Key "length" for array with keys "col1, artikel" does not exist error. {{entry.artikelnummer|length}} gives me: 2 1 1 1 1 0 0 0 0 0 1 1 0 1 1 1 1 1 1 0 1 2 1 0 1 1 2. I need the sum of them. – TomS Jan 27 '17 at 16:40
  • sorry, misread your question. updated the answer – Jan_dh Jan 27 '17 at 18:40
2

You can get the total amount of rows like this:

{% set totalcount = 0 %}
{% for entry in entries %}
    {% set totalcount = totalcount + entry.artikelnummer|length %} 
{% endfor %}

Edit

In the loop you add the length to the totalCount.

|improve this answer|||||
  • 1
    Thanks a lot! Had to add a {% set totalcount = 0 %} outside the loop and it worked! – TomS Jan 27 '17 at 22:06
  • @TomS I'll edit the answer so it's more clear for everyone ;) – Jan_dh Jan 27 '17 at 23:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.