eleventy
eleventy copied to clipboard
Directory Data File in Top Level Input Directory
It is not clear in the documentation how to name directory data file in top level of input directory. Page: https://www.11ty.dev/docs/data-template-dir/
--unput=.file should be.11tydata.jsonorproject-name.11tydata.json?--unput=./src/file should be.11tydata.jsonorsrc.11tydata.json?
Related issues:
- https://github.com/11ty/eleventy/issues/245
- https://github.com/11ty/eleventy/issues/935
- https://github.com/11ty/eleventy/issues/993
This still doesn't seem to be documented as at 13 July, 2023 (https://github.com/11ty/11ty-website/commit/dcf4410e37d370eceff0ce2142d602cba874f1d2).
But for anyone else who comes across this: if you have files under ./src, then the correct name for a corresponding directory data file seems to be src.11tydata.json (or src.11tydata.js, etc., for other data formats).
But how does one specify data for a subdirectory, say ./src/sub/subsub in src.11tydata.js, including "layout"? (Because sub/ and subsub/ can only contain .md files in my usecase.)
I have no idea - as I said, it's undocumented. Or was your question directed at the eleventy maintainers?
Workarounds until this one ships are to use global data or the Configuration API method to set global data:
https://www.11ty.dev/docs/data/#sources-of-data
- https://www.11ty.dev/docs/data-global/
- https://www.11ty.dev/docs/data-global-custom/
One more addition here, if your input directory is nested inside of your project directory (e.g. src), it is supported to use src/src.json for directory data files.
This feature is specifically when your input directory is ..
Punting this one out of 3.0, sorry!
Placing in the enhancement queue:
This repository is now using lodash style issue management for enhancements. This means enhancement issues will now be closed instead of leaving them open.
View the enhancement backlog here. Don’t forget to upvote the top comment with 👍!