Skip to content
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

Computed data: can’t access collection data that’s been generated by pagination #1138

Closed
paulrobertlloyd opened this issue Apr 29, 2020 · 4 comments
Labels
bug waiting-to-close Issue that is probably resolved, waiting on OP confirmation.

Comments

@paulrobertlloyd
Copy link
Contributor

Describe the bug
I have a global data file, venues.js, which I use to create pages from using pagination:

---
layout: venue
pagination:
  data: venues
  size: 1
  alias: venue
  addAllPagesToCollections: true
permalink: "venues/{{ venue.id }}/"
tags: venue
eleventyComputed:
  title: "{{ venue.title }}"
---

Using tags, I add these generated pages to a collection called venue.

For my events pages, I want to reference data in collections.venue, namely finding the venue which has the same id as the one in an event’s frontmatter. I tried doing this using computed data:

module.exports = {
  layout: 'event',
  permalink: 'events/{{ page.date | date: "%Y/%m" }}/{{ page.fileSlug }}/',
  tags: ['event'],
  eleventyComputed: {
    venue: data => data.collections.venue.find(venue => {
      return venue.id === data.venue_id;
    })
  }
};

This generates an error: Cannot read property 'find' of undefined. If, however, I query a collection that has not been generated using pagination, then I don’t get this error.

Is this a known limitation of computed data?

@paulrobertlloyd paulrobertlloyd changed the title Computed data: can’t access collection that’s been generated by pagination Computed data: can’t access collection data that’s been generated by pagination Apr 29, 2020
@zachleat zachleat added this to the Eleventy v0.11.0 milestone Apr 29, 2020
@zachleat zachleat added bug and removed needs-triage labels Apr 29, 2020
@zachleat
Copy link
Member

I mean, it is known now!

Also very fixable 👍🏻

@zachleat
Copy link
Member

@paulrobertlloyd What version of Eleventy were you using here? Were you using the new 0.11.0 beta 4?

zachleat added a commit that referenced this issue Apr 30, 2020
@zachleat
Copy link
Member

I believe this was fixed with Beta 4 and wrote a passing test to confirm. Can you retest if you were not updated?

@paulrobertlloyd
Copy link
Contributor Author

paulrobertlloyd commented Apr 30, 2020

I am using the latest beta, but turns out this is a duplicate of #1137. If I write the following, I can get the output I expect*:

venue: data => {
  const venues = data.collections.venue;
  if (venues !== undefined) {
    const thing = venues.find(venue => {
      const venue_id = venue.data.venue.address['plus-code'].toLowerCase();
      return venue_id === data.venue_id;
    });
    console.log('thing', thing);
  }
},

*Well, not the output I expect, I’m investigating that now, but I at least get access to the collection data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug waiting-to-close Issue that is probably resolved, waiting on OP confirmation.
Projects
None yet
Development

No branches or pull requests

2 participants