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

Templating with subfoldered global data using frontmatter variables #1741

Closed
jewellscott opened this issue Apr 20, 2021 · 2 comments
Closed

Comments

@jewellscott
Copy link

Describe the bug, expected behavior

I have a bunch of .json files in a subfolder under _data, so the file structure is _data/projects/projectid.json.

I'm pulling in data from these pages to populate a case study blog post, in which I specify a title, the layout, and the projectID.

I'm expecting {{ projects.projectID.title }} to give me the value of the title key in the file _/data/projects/cats.json if I specify projectID: 'cats' in the frontmatter, but it doesn't.

To Reproduce

  1. Calling {{ projectID }} in the template does populate with the projectID of cats as it should.
  2. Calling {{ projects.cats.title }} works, populating with the title of the Cats project.
  3. Calling {{ projects.projectID.title }} doesn't work. Theoretically, the template would populate projectID with cats as I have assigned and output like Install hangs - dependency slug-rfc asking for a passphrase #2, but it doesn't.

So to be clear, I get

  • {{ projectID }} cats
  • {{ projects.cats.title }} Cats: A fancy project title
  • {{ projects.projectID.title }} [ nothing ]

My guess is that eleventy is trying to find the title of a file called projectID.json that doesn't actually exist, but I have no idea how to circumvent that. I tried nesting the variable with handlebars and that returned errors. , and none of them worked. Any thoughts?

Additional context
My guess is that eleventy is trying to find the title of a file called projectID.json that doesn't actually exist, but I have no idea how to circumvent that. I tried nesting the variable with handlebars and that returned errors.

@pdehaan
Copy link
Contributor

pdehaan commented Apr 20, 2021

I’m not at a laptop, but try {{ projects[projectID].title }}.

@jewellscott
Copy link
Author

jewellscott commented Apr 20, 2021

I’m not at a laptop, but try {{ projects[projectID].title }}.

Thank you! I wish I would've just asked hours ago. Lol

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

No branches or pull requests

2 participants