I’m working on a new template which requires two “fori” loops nested within one other. What I need is something like a “Loans and leasings” template but where I can add multiple loans on the same account.
The first loop is used to create mutliple loans.
For that I use:
{% fori detail in current_account.details %} <— my loan → {% endfori %}
The second loop is located inside the first one and is used to create a table with the refunds, date, remaining capital, etc… For that I use:
{% assign items = custom.items %} {% fori item in items %} <— my table → {% endfori %}
NB: I need to have something like item.name, item.date, etc…
The problem with that code is that if I fill the table once, it stays the same for every new loan. And if I change the values of one loan, it changes for every other one.
From what I understand I should link the table to the current detail so that every new loan has its own table.
{% assign items = custom.items %}
{% fori item in items %} <— my table --> {% endfori %}
You could use (for example):
{% fori item in custom[loan.key] %}
This code attributes a key to each loan (in the example). We work like this in the ‘Deelnemingen’ account template. You could apply the same way of working.
Please let us know if this would not work for you or if you need our help. Could you then please post the piece of the code of the fori loops, or tell us the name of the template? So we can take a look at the full code in your collection.
Now I understand what went wrong. I thought you went 3 levels deep, but you only went 2 levels deep but are using 2 foriloops nested in another foriloop.
The problem here is that every custom variable needs to be unique.
Your original code looked something like this
{% fori meerwaarde in custom.meerwaardes %}
{% fori wederbeleggingid in custom[meerwaarde.key] %}
....
{% endfori %}
{% fori onttrekking in custom[meerwaarde.key] %}
....
{% endfori %}
{% endfori %}
The problem with this is that you are making 2 variable with the same name, because you are using meerwaarde.key twice. You need to make these keys unique. You can do this the following way: