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

V3: JSON-based content rendered as [object Object] #3131

Closed
ironnysh opened this issue Dec 20, 2023 · 8 comments
Closed

V3: JSON-based content rendered as [object Object] #3131

ironnysh opened this issue Dec 20, 2023 · 8 comments
Labels
bug: lite Debatable whether or not this is a bug. I mean, it’s not great but it’s not really broken either. bug-has-workaround Has an okay workaround to the issue for now common-pitfall-eligible Might need to be listed on the common problems docs page education

Comments

@ironnysh
Copy link

Operating system

macOS Sonoma 14.2

Eleventy

3.0.0-alpha.2

Describe the bug

Hi,
I was testing V3 and have just run into a weird bug:

I upgraded and converted a very minimal 11ty project to ESM, and the site seemingly builds as expected in development and production. However, while the JSON-based content is generated, it doesn't render. I get a mysterious [object Object] instead of the generated HTML.

I think the problem has to do with the template/layout:

  • When I change {{ content | safe }} to {{ content | log }} I can see the content in the terminal
  • When I change it to {{ content | dump }} I see it in my index.html.

The same problem occurs with a markdown file, so it's not just a Nunjucks-JSON issue.

Would appreciate any pointers :-) Thanks!

Reproduction steps

  1. The 11ty V2 repo is here. Here's the built site
  2. The 11ty V3 repo is here. Here's the built site

Expected behavior

No response

Reproduction URL

No response

Screenshots

No response

@Snapstromegon
Copy link
Member

Unrelated to this issue, which I didn't have the time to look at in detail:
Why are you putting your content in a json data file instead of templates that are in a collection?
So e.g. having a folder for services, with a directory data file putting all services into a services collection and one file per service?
I don't actually know if this is more maintainable, but it's what I've been doing in similar situations, since I want to keep longer chunks of content outside of my data.

@Snapstromegon
Copy link
Member

Hah! I found your bug!
I'm completely amazed that it even worked in 11ty v2, since you override the "content" variable (which holds the content of the child in a layout) with your data. Renaming your src/_data/content.json to e.g. src/_data/info.json (and changing the references in the templates) fixes the issue.

I personally don't think this was supposed to work in the old version anyways and because of this wouldn't consider this a bug, but definetly worth documenting.

@Snapstromegon Snapstromegon added education bug: lite Debatable whether or not this is a bug. I mean, it’s not great but it’s not really broken either. common-pitfall-eligible Might need to be listed on the common problems docs page bug-has-workaround Has an okay workaround to the issue for now and removed needs-triage labels Dec 20, 2023
ironnysh added a commit to ironnysh/mighty that referenced this issue Dec 20, 2023
* Fix error

* Rename content to texts (reserved for 11ty). See 11ty/eleventy#3131 (comment)
@ironnysh
Copy link
Author

Oh, wow 🤯Thank you! I changed src/_data/content.json to src/_data/texts.json and it works now.
So content is like page, reserved for 11ty?

@ironnysh
Copy link
Author

Sorry, @Snapstromegon, I forgot to answer your first question:
I wanted to avoid having extra folders and ~12 markdown files that contain content that probably makes more sense as frontmatter, anyway.
I did debate (with myself) about the About, but decided to go all in with JSON to keep it simple.

I've built other 11ty websites with much more content, where I'm using the standard practice you mentioned :-)

@Snapstromegon
Copy link
Member

Oh, wow 🤯Thank you! I changed src/_data/content.json to src/_data/texts.json and it works now. So content is like page, reserved for 11ty?

Yes, at least in layouts content should be reserved for 11ty.

@ironnysh
Copy link
Author

Good to know.
Shall I close this as complete or leave it open for this:

definetly worth documenting.

@Snapstromegon
Copy link
Member

Let's keep it open until we have a follow-up issue for documenting this behavior. I'm going to bed now, so if you want to, you can create that issue or leave it for me to do tomorrow.

@ironnysh
Copy link
Author

Done. Good night :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug: lite Debatable whether or not this is a bug. I mean, it’s not great but it’s not really broken either. bug-has-workaround Has an okay workaround to the issue for now common-pitfall-eligible Might need to be listed on the common problems docs page education
Projects
None yet
Development

No branches or pull requests

2 participants