New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom collection - can't return an object #277

Closed
edwardhorsford opened this Issue Oct 16, 2018 · 5 comments

Comments

Projects
None yet
2 participants
@edwardhorsford

edwardhorsford commented Oct 16, 2018

I'm trying to use a custom collection to return an object.

However, I get the following error:
> collections[collectionName] is not iterable (TypeError)

The docs state "addCollection callbacks can now return any arbitrary object type and it’ll be available as data in the template. Arrays, strings, objects—have fun with it." - this makes me think it should be fine to return an object.

I've tested with a fresh install of the base blog and adding a custom collection that returns an empty object, and an object with a key value pair.

For my personal site I've gotten around it by returning the object wrapped in an array. But this means when I access the data or paginate on it, I have to call collections.data[0].

The other thing I got to work was returning a Set - but while Eleventy works with it and does pagination on it, I'm struggling to get Nunjucks to iterate over the set.

@zachleat

This comment has been minimized.

Collaborator

zachleat commented Nov 17, 2018

HMMMM. Are you sure this isn’t a duplicate of #202? Seems like it was fixed in 0.5.3?

@edwardhorsford

This comment has been minimized.

edwardhorsford commented Nov 18, 2018

I'm pretty sure I'm running 0.5.4 - if I go in to node_modules/@11ty/eleventy/package.json it says 0.5.4. Anything else I can check?

Also - when I filed this I checked with a fresh install of the base blog - presumably that would have the latest anyway.

@edwardhorsford

This comment has been minimized.

edwardhorsford commented Nov 18, 2018

@zachleat - tried with another fresh install of the base blog - commit here. Returning a simple object (commented out) or empty object returns the error > collections[collectionName] is not iterable (TypeError)

@zachleat zachleat removed the open-question label Nov 18, 2018

@zachleat

This comment has been minimized.

Collaborator

zachleat commented Nov 18, 2018

Thanks for double checking! Filed as a bug

@zachleat zachleat self-assigned this Nov 22, 2018

@zachleat zachleat added this to the v0.6.0 milestone Nov 22, 2018

@zachleat zachleat closed this in 7cac4ac Nov 22, 2018

@zachleat

This comment has been minimized.

Collaborator

zachleat commented Nov 22, 2018

Look for this in 0.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment