# Nested foriloops with account\_collection

**URL:** <https://community.silverfin.com/t/nested-foriloops-with-account-collection/2208>\
**Category:** Templates\
**Tags:** for\_loop, drop\_accounts\
**Created:** [February 11, 2022, 1:03pm UTC](https://community.silverfin.com/t/nested-foriloops-with-account-collection/2208 "2022-02-11T13:03:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![b.dalle](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/b.dalle/32/2305_2.png) [@b.dalle](https://community.silverfin.com/u/b.dalle)\
**Post date:** [February 11, 2022, 1:03pm UTC](https://community.silverfin.com/t/nested-foriloops-with-account-collection/2208/1 "2022-02-11T13:03:06Z")

</div>

Hello,

I am working on a template which requires 2 foriloops in combination with an account\_collection.  
The code below works, however if I change an inputfield, it also overwrites the same account in the following loop.

```auto
{% fori best in custom.bezoldigingstest %}{% input best.naam %} {% input best.rekeningen as:account_collection range:61 accounts_var:bez_rek %}

{% fori rek in bez_rek %}{% if forloop.first %}
|Rek.nummer|Rek.naam|Bedrag|
|------|------|------:+{% endif %}
|{{ rek.number }}|{% input rek.custom.bezoldiging.omschrijving default:rek.name%}|{% input rek.custom.bezoldigings.bedrag as:currency default:rek.value%}{% endfori %}

{% endfori %}

```

I suppose I should include a key for the second foriloop, however i can’t get it to work properly.  
Is there a way to do this?

---

<div class="post-metadata">

**Author:** ![borjaGonzalez](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/borjagonzalez/32/825_2.png) [@borjaGonzalez](https://community.silverfin.com/u/borjaGonzalez)\
**Post date:** [February 11, 2022, 1:25pm UTC](https://community.silverfin.com/t/nested-foriloops-with-account-collection/2208/2 "2022-02-11T13:25:06Z")

</div>

Hi @b.dalle,

You should indeed use a key from the first foriloop (`best.key`). This should work:

```auto
{% fori best in custom.bezoldigingstest %}
  {% input best.naam %} 
  {% input best.rekeningen as:account_collection range:1 accounts_var:bez_rek %}

  {% fori rek in bez_rek %}
    {% if forloop.first %}
      |Rek.nummer|Rek.naam|Bedrag|
      |------|------|------:+
    {% endif %}
    |{{ rek.number }}
    |{% input rek.custom.[best.key].omschrijving default:rek.name %}
    |{% input rek.custom.[best.key].bedrag as:currency default:rek.value%}
  {% endfori %}
{% endfori %}

```

Should you have any other queries, please let us know.

Best,  
Borja

---

<div class="post-metadata">

**Author:** ![b.dalle](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/b.dalle/32/2305_2.png) [@b.dalle](https://community.silverfin.com/u/b.dalle)\
**Post date:** [February 11, 2022, 1:34pm UTC](https://community.silverfin.com/t/nested-foriloops-with-account-collection/2208/3 "2022-02-11T13:34:29Z")

</div>

Works like a charm! Thx Borja!
