Putting dates in arrays

Gentlemen,

In a reconciliation template, I put some dates in an array in this way (for directors):

{% if person.director_start_date == empty %}{{colours_red}}geen begindatum{% else %}{{person.director_start_date | date:'%d/%m/%Y'}}{% endif %}
{% comment %}Step: stel voor de leidinggevenden de begindatum van het mandaat vast{% endcomment %}
{% if person.director_start_date == empty %}
{% assign str_AlleLeidinggevenden_Mandaten_Startdata = str_AlleLeidinggevenden_Mandaten_Startdata | append:'geen begindatum' | append:'|' %}
{% else %}
{% assign str_AlleLeidinggevenden_Mandaten_Startdata = str_AlleLeidinggevenden_Mandaten_Startdata | append:{{person.director_start_date}} | append:'|' %}
{% endif %}

This happened for a few dates. At the end, I removed the last separator

{% assign str_AlleLeidinggevenden_Mandaten_Startdata = str_AlleLeidinggevenden_Mandaten_Startdata | slice: 0, str_AlleLeidinggevenden_Mandaten_Startdata.size-1 %}

I also put this string in a result tag

{% result 'str_AlleLeidinggevenden_Mandaten_Startdata' str_AlleLeidinggevenden_Mandaten_Startdata %}

In another (text) template, I wanted to give an overview of these dates

{% assign str_AlleLeidinggevenden_Mandaten_Startdata = period.reconciliations.BedPar_Ref.results.str_AlleLeidinggevenden_Mandaten_Startdata %}
{% assign str_AlleLeidinggevenden_Mandaten_Startdata = str_AlleLeidinggevenden_Mandaten_Startdata | split:'|' %}
arr_AlleLeidinggevenden_Mandaten_Startdata: {{ arr_AlleLeidinggevenden_Mandaten_Startdata }}

Now, my question: with text data, this approach works fine. However, with dates, this doesn’t appear to work. Do I have to do some additional manipulation first before putting the dates in a string?

Thanks and have a great weekend!

Hi @Bart_Verhaeghe,

Could it be related to this code :

{% assign str_AlleLeidinggevenden_Mandaten_Startdata = period.reconciliations.BedPar_Ref.results.str_AlleLeidinggevenden_Mandaten_Startdata %}
{% assign str_AlleLeidinggevenden_Mandaten_Startdata = str_AlleLeidinggevenden_Mandaten_Startdata | split:'|' %}
arr_AlleLeidinggevenden_Mandaten_Startdata: {{ arr_AlleLeidinggevenden_Mandaten_Startdata }} 

You assign the var str_AlleLeidinggevenden_Mandaten_Startdata but in the test you use another variable called arr_AlleLeidinggevenden_Mandaten_Startdata
Is this the reason?

Also, if it’s exactly the output of some code you want to display in another template, you could also use a capture:

{% capture dates_directors %}
{% for person in period.directors %}
{% if person.director_start_date == empty %}{{colours_red}}geen begindatum{% else %}{{person.director_start_date | date:'%d/%m/%Y'}}{% endif %}
{% comment %}Step: stel voor de leidinggevenden de begindatum van het mandaat vast{% endcomment %}
{% if person.director_start_date == empty %}
{% assign str_AlleLeidinggevenden_Mandaten_Startdata = str_AlleLeidinggevenden_Mandaten_Startdata | append:'geen begindatum' | append:'|' %}
{% else %}
{% assign str_AlleLeidinggevenden_Mandaten_Startdata = str_AlleLeidinggevenden_Mandaten_Startdata | append:{{person.director_start_date}} | append:'|' %}
{% endif %}
{% endfor %}
{% endcapture %}

{% result 'dates_directors' dates_directors %} 

Outcome in another template:

{% assign str_AlleLeidinggevenden_Mandaten_Startdata = period.reconciliations.community.results.dates_directors %}

test = 
{{ str_AlleLeidinggevenden_Mandaten_Startdata }} 

Let me know it this helped

Well, should have seen this myself. What can I say :-)?

Thanks Sven!