Answers.Body: <p>I figured this out, with help from a GitHub thread or too. It appeared that using the <code>sort</code> filter on an array of objects was problematic. I was able to fix this by sorting the keys in <code>speakers</code> instead of directly sorting <code>speakers</code>.</p>
  
  <p><strong>Working code</strong>:</p>
  
  <pre><code>{% for speakerKey in speakers|keys|sort %}
    {% set speaker = speakers[speakerKey] %}
  
    &lt;li&gt;{{ speaker.title }}&lt;/li&gt;
  {% endfor %}
  </code></pre>
  
  <p>I'm not 1000% sure <em>exactly</em> what was breaking, but I think by using <code>|sort</code> on a collection of objects, PHP ended up recursively looping through the <code>speakers</code> array in an attempt to sort it.</p>
  
  <p>Here are some related threads that I pieced together to guess that <code>|sort</code> was the problem:</p>
  
  <ul>
  <li><a href="https://craftcms.stackexchange.com/questions/10294/nesting-level-too-deep-when-looping-through-matrix-blocks">Nesting level too deep when looping through matrix blocks</a></li>
  <li><a href="https://stackoverflow.com/questions/3834791/fatal-error-nesting-level-too-deep-recursive-dependency">https://stackoverflow.com/questions/3834791/fatal-error-nesting-level-too-deep-recursive-dependency</a></li>
  <li><a href="https://github.com/craftcms/cms/issues/5794" rel="nofollow noreferrer">https://github.com/craftcms/cms/issues/5794</a></li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-02T20:16:12.513Z
Answers.LastActivityDate: 2020-04-02T20:23:08.943Z
Answers.LastEditDate: 2020-04-02T20:23:08.943Z
Answers.UserDisplayName: Jake Dohm
Body: <p>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".</p>
  
  <p><strong>Here's (a reduction of) the code:</strong></p>
  
  <pre><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 %}
  
  </code></pre>
  
Tags: <yii><sort>
Title: Nesting level too deep - recursive dependency?
ThreadText: # Nesting level too deep - recursive dependency?
  
  (Asked by: username_0 on 2020-04-02)
  
  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 => s.state.one().slug) %}
  {% for state, speakers in speakersByState %}
    <ul>
      {% for speaker in speakers|sort %}
        <li>{{ speaker.title }}</li>
      {% endfor %}
    </ul>
  {% endfor %}
  
  ```
  
  **Tags:** yii, sort
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2020-04-02. Score: 2
  
  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] %}
  
    <li>{{ speaker.title }}</li>
  {% 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://craftcms.stackexchange.com/questions/10294/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>
  
  
  ---
  
  