Im trying to get something in a table here.
The case: when the mandate of a director has expired for more than 730 days, he should no longer show the director in our table.
I made the following code:
{% assign mandaat_bedrijfsleider_vervaldatum = director.director_end_date | date:"%d/%m/%Y" %}
{% assign today = "now" | date: "%d/%m/%Y" %}
{% assign mandaat_bedrijfsleider_vervallen = today-mandaat_bedrijfsleider_vervaldatum %}
{% if mandaat_bedrijfsleider_vervallen >= 730 %}Het mandaat is meer dan 2 jaar vervallen{% endif %}
{% endfor %}```
```{% stripnewlines %}
{% newline %}
|Bedrijfsleiders
|Begin mandaat
|Einde mandaat
{% newline %}
|---
|---:
|---:
{% ic %}#{% endic %}{% nic %}+{% endnic %}{% for director in period.directors%}
{% if mandaat_bedrijfsleider_vervallen >= 730 %}{%else%}
{% assign words = director.name | split: ' ' %}
{% assign lastname = "" %}
{% assign person_first_name = "" %}
{% assign current_signature = "" %}
{% for word in words %}
{% if forloop.last %} {% comment %}correct for syncs like adminis{% endcomment %}
{% assign person_first_name = word %}
{% else %}
{% assign lastname = lastname | append:" " | append:word %}
{% endif %}
{% endfor %}
{% endif %}
{% newline %}
{% if mandaat_bedrijfsleider_vervallen >= 730 %}{%else%}
{% if director.custom.first_name == blank and director.custom.last_name == blank %}
{% assign current_signature = director.name %}
{% elsif director.custom.first_name == blank and director.custom.last_name != blank %}
{% assign current_signature = director.name %}
{% elsif director.custom.first_name != blank and director.custom.last_name == blank %}
{% assign current_signature = director.name %}
{% else %}
{% assign current_signature = current_signature | append:director.custom.first_name | append:" " | append:director.custom.last_name %}
{% endif %}
{% if director.custom.represented_by_name != blank %}
{% assign default_type = "legal" %}
{% else %}
{% assign default_type = "nature" %}
{% endif %}
{% assign type = director.custom.type | default:default_type %}
|{{ current_signature }}{% if type == "legal" and director.custom.represented_by_name != blank %} met als vaste vertegenwoordiger {{ director.custom.represented_by_name }}{% endif %}
|{{ director.director_start_date | date:"%d/%m/%Y" }}
|{{ director.director_end_date | date:"%d/%m/%Y" }}
{% endif %}
{% endfor %}
{% endif %}
{% endstripnewlines %}```
When I only have 1 director, it works, but with multiple it doesn't :frowning:
Thx!
The local variable mandaat_bedrijfsleider_vervallen is updated every iteration (i.e. for each director).
So if the mandate for the first director has expired, but for the second it hasn’t, the end value of the local variable will be equal to that of the second, which hasn’t expired.
You can resolve this by assigning a new local variable mandaat_bedrijfsleider_vervallen for each director.
Your first for-loop should be like:
{% for director in period.directors %}
{% assign mandaat_bedrijfsleider_vervaldatum = director.director_end_date | date:"%d/%m/%Y" %}
{% capture mandaat_bedrijfsleider_vervallen %}mandaat_{{ director.key }}{% endcapture %}
{% assign [mandaat_bedrijfsleider_vervallen] = today-mandaat_bedrijfsleider_vervaldatum %}
{% if [mandaat_bedrijfsleider_vervallen] >= 730 %}Het mandaat is meer dan 2 jaar vervallen{% endif %}
{% endfor %}
Notice the brackets [] used in the third and fourth lines. These enable us to use a variable name that changes with the director.
Within your second forloop you can always call the director-specific local variables by entering the capture statement again:
Try to wrap the entire table line you want to hide, within an if statement, which is conditional on your director expiration variable.
Make sure you have first determined the local variables for each director in the first loop! Only then you can call these using the capture statement a second time.
Don’t hesitate to ask if you still encounter problems.
{% stripnewlines %}
{% newline %}
|Bedrijfsleiders
|Begin mandaat
|Einde mandaat
{% newline %}
|---
|---:
|---:{% ic %}#{% endic %}{% nic %}+{% endnic %}
{% for director in period.directors %}
{% capture mandaat_bedrijfsleider_vervallen %}mandaat_{{ director.key }}{% endcapture %}
{% if [mandaat_bedrijfsleider_vervallen] < 730 %}
{% assign words = director.name | split: ' ' %}
{% assign lastname = "" %}
{% assign person_first_name = "" %}
{% assign current_signature = "" %}
{% for word in words %}
{% if forloop.last %} {% comment %}correct for syncs like adminis{% endcomment %}
{% assign person_first_name = word %}
{% else %}
{% assign lastname = lastname | append:" " | append:word %}
{% endif %}
{% endfor %}
{% newline %}
{% if director.custom.first_name == blank and director.custom.last_name == blank %}
{% assign current_signature = director.name %}
{% elsif director.custom.first_name == blank and director.custom.last_name != blank %}
{% assign current_signature = director.name %}
{% elsif director.custom.first_name != blank and director.custom.last_name == blank %}
{% assign current_signature = director.name %}
{% else %}
{% assign current_signature = current_signature | append:director.custom.first_name | append:" " | append:director.custom.last_name %}
{% endif %}
{% if director.custom.represented_by_name != blank %}
{% assign default_type = "legal" %}
{% else %}
{% assign default_type = "nature" %}
{% endif %}
{% assign type = director.custom.type | default:default_type %}
|{{ current_signature }}{% if type == "legal" and director.custom.represented_by_name != blank %} met als vaste vertegenwoordiger {{ director.custom.represented_by_name }}{% endif %}
|{{ director.director_start_date | date:"%d/%m/%Y" }}
|{{ director.director_end_date | date:"%d/%m/%Y" }}
{% endif %}
{% endfor %}
{% endstripnewlines %}