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

Documentation: The word "content" is reserved for 11ty in layouts #3132

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

Documentation: The word "content" is reserved for 11ty in layouts #3132

ironnysh opened this issue Dec 20, 2023 · 9 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 duplicate error-messaging

Comments

@ironnysh
Copy link

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.

Originally posted by @Snapstromegon in #3131 (comment)

@uncenter
Copy link
Contributor

I would go as far as to say having a DATA_DIR/content.{js,json} file should throw an error, and the same for other reserved keywords.

@uncenter
Copy link
Contributor

Seems pretty doable: https://github.com/uncenter/11ty-fork/blob/feat/reserved-keyword-global-data-throw/src/TemplateData.js#L330-L336.

Not sure how to find what keys are reserved though, those are just manual.

@Snapstromegon Snapstromegon added 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 error-messaging bug-has-workaround Has an okay workaround to the issue for now labels Dec 21, 2023
@Snapstromegon
Copy link
Member

@uncenter
Nice first version for global data, but if we block it in global data, IMO we should block it in ALL top level data (e.g. frontmatter and co.). Sadly I'm unsure how the "content" variable gets used in layouts and if it's just as easy to implement this feature for all data while not breaking how layouts currently work.

@uncenter
Copy link
Contributor

That's why I was just thinking global data for now.

@Snapstromegon
Copy link
Member

I just took a look and found that the content variable is set directly before passing the data into a layout here: https://github.com/11ty/eleventy/blob/main/src/TemplateLayout.js#L229
This means we could block setting any top level data entry to a reserved keyword.
Maybe we could do it here: https://github.com/11ty/eleventy/blob/main/src/TemplateLayout.js#L229 or here: https://github.com/11ty/eleventy/blob/main/src/TemplateData.js#L508

I'm unsure whether or not this works with computed data.

@zachleat
Copy link
Member

https://github.com/11ty/eleventy/tree/frozen-reserved-data has some of the start of this, freezing pkg and eleventy data. More to come.

@zachleat zachleat added this to the Eleventy 3.0.0 milestone Apr 12, 2024
@zachleat
Copy link
Member

Let’s regroup on this one over at #1173.

@zachleat
Copy link
Member

Fixed by #3251 Shipping with 3.0.0-alpha.7

@ironnysh
Copy link
Author

Thanks, @zachleat!

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 duplicate error-messaging
Projects
None yet
Development

No branches or pull requests

4 participants