1

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 %}

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:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.