Beroepskosten 2.0 - default accounts with categories

Great case @Cedric!

Okay, here it goes, step by step:

If you do a forloop like this :

{% for cost_category in cost_categories %}
{{ cost_category }} 
{% endfor %}

gives this result :

05

Now, we use the tags from cost_keys however, and the way to link them between cost_categories and cost_keys, is using a [forloop.index0]:

{% for cost_category in cost_categories %}
{{ cost_category }} - {{ cost_keys[forloop.index0] }}
{% endfor %}

gives this result :

17

So, when you go to the first iteration of loops around your object cost_categories, you’ll also will go to the first iteration of loops of the object cost_keys.
If it’s your second iteration of loops of cost_categories, you’ll do the same for cost_keys, and so on… That’s the way to link between 2 different objects like cost_categories and cost_keys.

We can do the same now for our default-string we want to use to get the default account range:

{{ cost_default[forloop.index0] }}

So, if you add this in the forloop that generates every type of cost ( {% for cost_category in cost_categories %} ) :

{% assign category_default = cost_default[forloop.index0] %}

then you can use that category_default variable as your default account range :

{% input custom[category_key].accounts as:account_collection range:6,7 default:category_default  accounts_var:costs %}

Can you try to have a spin on this @Cedric? Great case to expand the template of “beroepskosten” :ok_hand: