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

**URL:** https://community.silverfin.com/t/nested-fori-loop-error-liquid-error-undefined-method-split-for-nil-nilclass/1704
**Category:** Templates
**Created:** [March 24, 2020, 3:33pm UTC](https://community.silverfin.com/t/nested-fori-loop-error-liquid-error-undefined-method-split-for-nil-nilclass/1704 "2020-03-24T15:33:32Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Abo](https://avatars.discourse-cdn.com/v4/letter/a/fbc32d/32.png) [@Abo](https://community.silverfin.com/u/Abo)
#### Post date: [March 24, 2020, 3:33pm UTC](https://community.silverfin.com/t/nested-fori-loop-error-liquid-error-undefined-method-split-for-nil-nilclass/1704/1 "2020-03-24T15:33:32Z")

</div>

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

---

<div class="post-metadata">

### Author: ![sven](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/sven/32/1495_2.png) [@sven](https://community.silverfin.com/u/sven)
#### Post date: [March 24, 2020, 6:55pm UTC](https://community.silverfin.com/t/nested-fori-loop-error-liquid-error-undefined-method-split-for-nil-nilclass/1704/2 "2020-03-24T18:55:31Z")

</div>

Hey @Abo,

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

```auto
{% 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 😬 ) :

```auto
{% 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 😊

---

<div class="post-metadata">

### Author: ![Abo](https://avatars.discourse-cdn.com/v4/letter/a/fbc32d/32.png) [@Abo](https://community.silverfin.com/u/Abo)
#### Post date: [March 24, 2020, 7:59pm UTC](https://community.silverfin.com/t/nested-fori-loop-error-liquid-error-undefined-method-split-for-nil-nilclass/1704/3 "2020-03-24T19:59:08Z")

</div>

> [@sven](#):
>
> {% capture bene\_key %}bene\_{{ item.key }}{% endcapture %}

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

---

<div class="post-metadata">

### Author: ![sven](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/sven/32/1495_2.png) [@sven](https://community.silverfin.com/u/sven)
#### Post date: [March 24, 2020, 8:00pm UTC](https://community.silverfin.com/t/nested-fori-loop-error-liquid-error-undefined-method-split-for-nil-nilclass/1704/4 "2020-03-24T20:00:54Z")

</div>

Fantastic to hear! 🙌

---

<div class="post-metadata">

### Author: ![sven](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/sven/32/1495_2.png) [@sven](https://community.silverfin.com/u/sven)
#### Post date: [March 24, 2020, 8:01pm UTC](https://community.silverfin.com/t/nested-fori-loop-error-liquid-error-undefined-method-split-for-nil-nilclass/1704/5 "2020-03-24T20:01:05Z")

</div>


