I’m trying to sort a collection by custom front matter but am getting an error - Liquid Exception: stack level too deep in index.html.
I have collection called procedures, works fine without the sort.
I have front matter in each collection item like: sort: 1
then I am looping thru them like:
{% assign sorted = site.procedures | sort: 'sort' %}
{% for item in sorted %}
<p><a href="{{item.url}}"><h3>{{item.title}}</h3></a><p>
{% endfor %}
If I copy those collection files and put them in a test folder - not a collection, and change the above code in the assign part to site.pages it works properly.
But as a collection it does not work.
If I change the sort from my custom variable to title it works fine.
It just won’t work on a custom variable on a collection.
Hey @rdyar! You probably already tried this and it’s very unlikely to be the root cause, but just in case, I came across a similarly weird and obscure issue a few years ago and in that case it turned out to be a naming conflict.
So I might do a quick test by changing your front matter variable from sort to foo to quickly isolate that as the source.
This is an undocumented issue that may get fixed in a future release. But as of v4.1.0, this behavior is applicable to both pages and collection documents.
One will encounter this issue if they iterate through the same type of object as the container.
Examples:
site.pages | sort 'sort' inside a standalone page say, about.md or
site.posts | sort 'sort' inside a post or
site.recipes | sort 'sort' inside a document within collection recipes .
The behavior will manifest for the following parameter values: 'sort' , 'min' , 'max' .