Nesting level too deep - recursive dependency? I've got a page with a couple of levels of loops. It takes a section of speakers, groups them by state, and then loops through the states, and then loops through speakers in that state. It's not too complex so I wouldn't expect to see an error like "nesting too deep".

Here's (a reduction of) the code:

{% set speakersByState = speakers|group(s =&gt; s.state.one().slug) %}
{% for state, speakers in speakersByState %}
  &lt;ul&gt;
    {% for speaker in speakers|sort %}
      &lt;li&gt;{{ speaker.title }}&lt;/li&gt;
    {% endfor %}
  &lt;/ul&gt;
{% endfor %}
I figured this out, with help from a GitHub thread or too. It appeared that using the sort filter on an array of objects was problematic. I was able to fix this by sorting the keys in speakers instead of directly sorting speakers.

Working code:

{% for speakerKey in speakers|keys|sort %}
  {% set speaker = speakers[speakerKey] %}

  &lt;li&gt;{{ speaker.title }}&lt;/li&gt;
{% endfor %}


I'm not 1000% sure exactly what was breaking, but I think by using |sort on a collection of objects, PHP ended up recursively looping through the speakers array in an attempt to sort it.

Here are some related threads that I pieced together to guess that |sort was the problem:


Nesting level too deep when looping through matrix blocks
https://stackoverflow.com/questions/3834791/fatal-error-nesting-level-too-deep-recursive-dependency
https://github.com/craftcms/cms/issues/5794