Swatch.Liquid "Nesting Too Big"

Shopify Partner
3 0 0

Hey Guys,

First post here...

 

Long story short, on my product page, it had an error under the product so I tried changing that. I got it to go away but now it says "Liquid Error: Nesting too deep". Does anyone know what is wrong with my code and how I can fix this?

 

Here is my code now...

{% if product.available and product.variants.size > 1 %}
{% for option in product.options %}
{% include 'swatch' with option %}
{% endfor %}
{% endif %}

0 Likes
Highlighted
Shopify Partner
1843 170 534

Never came across that one, but you're probably nesting to many loops within loops within loops within... you get the gist. Without knowing within what context that bit of code is run and what's done in the snippet you're including, it's hard to tell - I'd suggest you start by commenting out bottom up or top down until you locate the part of your theme that's causing this issue then look for ways to fix or provide more context here for further help from forum members.

I turn coffee in to code - since 1998
0 Likes
Shopify Partner
3 0 0

Screen Shot 2019-03-10 at 9.49.39 PM.png

 

Heres a screenshot... hopefully this will help. Thank you 

0 Likes
Shopify Expert
9965 84 1465

So your swatch.liquid file is including swatch.liquid. That can open the door to some fun recursive loading. The error message makes sense.

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
0 Likes
Shopify Partner
3 0 0

thank you! any chance you know how i can change that>

0 Likes
Shopify Partner
247 9 49

Nesting too big (i got this recently) means there is something which is calling itself recursively and it does that too many times, thus nesting too deeply without any cap on how many iterations it does. This usually only happens with recursive code.

You have this snippet called 'swatch' which, within a loop, is including the same snippet called swatch, which is including the same snippet called swatch, on and on and on... this produces a nested hierarchy without limit, so shopify checks for that and puts a cap on it. You get the error because you have created an infinite situation that can never end.

0 Likes