Cannot use variable to get an item from an array "default_sub_array[position_nbr]"

Hi,

I have an array with accounts. But as the accounts can be .001, .002 etc the following arrays will not work.
So my plan is to get the index number of the account, and use this index to get the right item from another array.
I manage to get the index number, and I know that [0] for example gives the first item in the array. So I want to use the index number in the []. But it does not work.
Below I call this [position_nbr]. So when printing {{ position_nbr }} I get an integer, but it does not seem that liquid understands it when I use it in the brackets.
Any suggestions how to make liquid understand that position_nbr is an integer?

CODE

{% capture key_array %}key_001;key_002;key_003;key_004;key_005;key_006;key_007;key_008{% endcapture %}
{% capture account_array %}598000,599000,699300;607000,607100,607200,763100,763200;634000,634100,634200;642200,642300,655000,658000;698000,698100,698200;762200,762300;842300;509900,519900,690000,699200,769000,850000,860000,900000{% endcapture %}
{% capture default_array %}no,no,yes;no,no,yes,no,yes;no,no,yes;no,no,no,no;no,no,no;no,yes;yes;yes,yes,yes,yes,no,no,no,no{% endcapture %}

{% assign key_array = key_array | split:’;’ %}
{% assign account_array = account_array | split:’;’ %}
{% assign default_array = default_array | split:’;’ %}

{% for item in key_array %}
{% assign tot_accounts = period.accounts.include_zeros | range:account_array[forloop.index0] %}
{% assign accounts_sub_array = account_array[forloop.index0] %}
{% assign accounts_sub_array = accounts_sub_array | split:’,’ %}
{% assign default_sub_array = default_array[forloop.index0] %}
{% assign default_sub_array = default_sub_array | split:’,’ %}

{% for account in tot_accounts %}
  {% capture accountnbr %}{{ account.number }}{% endcapture %}

  {% capture accountnbr_six %}{{ accountnbr | slice:0,6 }}{% endcapture %}  

key = {{ item }}
account.number = {{ account.number }}
accountnbr_six = {{ accountnbr_six }}
{% for account in accounts_sub_array %}
{% if account == accountnbr_six %}
{% assign position = forloop.index %}
position = {{ position }}
{% assign position_nbr = position-1 | integer %}
position_nbr = {{ position_nbr }}
{% assign default_value = default_sub_array[position_nbr] %}
default_value för position {{ position }}= {{ default_value }}
{% break %}
{% endif %}
{% endfor %}
{% endfor %}
{% endfor %}

Kind regards,
Anna

Hi @ahaegglund,

Please try:

{% assign position_nbr = INT(position-1) %}

instead of using the | integer filter.

Does this help?

Thank you Melle, this works fine