Nested Fori Loop Error: Liquid error: undefined method `split' for nil:NilClass

Hi,
We have an issue with the fori loop, I’m sending a shorter version of the template:

First fori loop:

{% fori firstfori in custom.beneficiary %}
{% t “benif” %}
{% input firstfori.bene placeholder:‘beneficiary’ as:text %}
{% newline %}
{% t “choice” %}
{% input firstfori.dropdown as:select options:‘choice2’ %}
{% endfori %}

Second fori

{% fori secondfori in custom[firstfori.key] %}
{% input secondfori.date1.end_contract placeholder:“Date” as:date %}
{% endfori %}

Third fori nested in second fori

{% fori thirdfori in custom[secondfori.key] %}
{% input thirdfori.income_code placeholder:" / " %}
{% endfori %}

The error we are getting is: Liquid error: undefined method `split’ for nil:NilClass
If I change the second without using .key I’m getting as error:
Liquid error: Custom values can only go two levels deep

Is there any other solution ?
Thx

Hey @Abo,

The issue presents itself in this code (goes for second and third fori-loops by the way):

{% fori secondfori in custom[firstfori.key] %}
{% input secondfori.date1.end_contract placeholder:“Date” as:date %}
{% endfori %} 

The custom[firstfori.key] cannot really exists, as the firstfori is what? It isn’t made, as you are outside the code from the very first forloop.

You are doing a nested forli-loops, right? May I suggest the following (and also, please check our coding guidelines, as the naming of certain code is a little bit misleading, if you don’t mind me saying :grimacing: ) :

{% comment %}original FORI{% endcomment %}
{% fori item in custom.beneficiary %}
  {% input item.name_beneficiary placeholder:"beneficiary" %}
{% endfori %}

{% comment %}
next up, is to loop over each loop from the FIRST
now, what makes each loop from the FIRST unique, is indeed the key. 
and we will use that value to create an extra custom collection, as collections can only go one level deep
{% endcomment %}
{% for item in custom.beneficiary %}
  {{ item.name_beneficiary }}
  {% comment %}create unique collection with key of loop{% endcomment %}
  {% capture bene_key %}bene_{{ item.key }}{% endcapture %}
  {% comment %}create extra fori-loop (aka nested fori loop){% endcomment %}
  {% fori item in custom[bene_key] %}
    {% input item.contract_date as:date %}
  {% endfori %}
{% endfor %} 

Is this something you can built upon further? Let me know what you exactly are trying to built (probably a collection to enter beneficiaries, and each one need to be able to enter multiple dates; something like that), and I might be able to explain it better though :blush:

Hi Thx it works !
note: the naming was just as example :slight_smile:

Fantastic to hear! :raised_hands: