Counting number of loops

Hello again,

I have some trouble with the next code:

Bestuurder{% if bestuurdersaantal > 1 %}s{% endif %}:
{% assign bestuurdersaantal = 0 %}
{% fori x in custom.bestuurders %}
{% input x.persoon %}{% assign bestuurdersaantal = bestuurdersaantal | plus:1 %}{% endfori %}

So i want to count the number of loops with ‘bestuurdersaantal’ and i want to use that count for the title
‘Bestuurder of Bestuurders’ if there are 2 or more loops

However, It seems to work from top to bottom so I can’t use the ‘bestuurdersaantal’ above the code of the count.

Is there an other way to do this or do is it better to use ‘bestuurder(s)’?

Kind regards.

You can use .count like this

Bestuurder{% if custom.bestuurders.count > 1 %}s{% endif %}:
{% fori x in custom.bestuurders %}
  {% input x.persoon %}
{% endfori %}

It will however only work after saving.

Hope this helps :slight_smile:

That worked perfectly Sam

Thank you!!

Hello,

I have a simular question, but now in the template of ‘Huur Gebouwen’. I want to add text, but only when there are more than 1 year in the line of “Grens”.

{% for year in period.calendar_years %}{% assign start_date = MAX(year.start_date;detail.start_datum) %}{% if detail.eind_datum != blank %}{% assign end_date = MIN(year.end_date;detail.eind_datum) %}{% else %}{% assign end_date = year.end_date %}{% endif %}{% assign amount_of_days = end_date+1-start_date %}{% if amount_of_days > 0 %}{% capture revalorisatie_key %}rev_{{ year.end_date | date:'%Y' }}{% endcapture %}
||{% t "Grens" %} {{ year.end_date | date:'%Y' }} | = {{ beroeps_ki | currency }} x 5/3 x {{ [revalorisatie_key] | currency }} x {{ amount_of_days | integer }}/{{ year.amount_of_days_in_full_year | integer}} =|{%=$1+ beroeps_ki*5/3*[revalorisatie_key]*amount_of_days/year.amount_of_days_in_full_year | round | currency %}{% endif %}{% endfor %}

I have tried the code

{% if period.calendar_years.count > 1 %}bijkomende tekst{% endif %}

But that doesn’t work. Can you help me with that?

Hi

In this case you need to use period.calendar_years.size.

Kind regards
Sam