Error: undefined is not iterable (cannot read property Symbol(Symbol.iterator)) #1775
-
What I am trying to do is make an index page showing a list of links to all pages with a certain tag and then on my page I do ---
layout: index-list-page.html
type: face
--- and on the 'index-list-page' layout page I do ---
layout: default.html
---
<div class="container">
<ul class="index-list">
{%- assign indexList = collections['type'] -%}
{%- for i in indexList -%}
<li>{{ i.url }}</li>
{%- endfor -%}
</ul>
</div>
{{ content }} everything works fine but when I try the above while using my custom filter {%- assign indexList = collections['type'] | sortByAlph -%} eleventyConfig.addFilter("soryByAlph", function(values) {
let vals = [...values];
return vals.sort(function (a, b) {
let nameA = a.data.pageName?.toUpperCase();
let nameB = b.data.pageName?.toUpperCase();
if (nameA < nameB) return -1;
else if (nameA > nameB) return 1;
else return 0;
}); I get the following error Am I missing something? Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Off the top of my head, I wonder if it's possibly just a typo ( {%- assign indexList = collections['type'] | sortByAlph -%} versus // Should this be "sortByAlph"?
eleventyConfig.addFilter("soryByAlph" Or, possibly the "undefined is not iterable" is referring to the
You might need an additional check to see if |
Beta Was this translation helpful? Give feedback.
Off the top of my head, I wonder if it's possibly just a typo (
sortByAlph
vssoryByAlph
in your code above):versus
Or, possibly the "undefined is not iterable" is referring to the
collections['type']
returning undefined (unneeded single quotes around thattype
variable) causing the result to be undefined and then trying to call.sort()
on an undefined object...You might need an additional check to see if
vals
is an array before trying to call.sort()
. I'd have to test it out locally to see what you …