eleventy icon indicating copy to clipboard operation
eleventy copied to clipboard

Directory Data File in Top Level Input Directory

Open mahnunchik opened this issue 4 years ago • 5 comments

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/

  1. --unput=. file should be .11tydata.json or project-name.11tydata.json?
  2. --unput=./src/ file should be .11tydata.json or src.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

mahnunchik avatar Dec 06 '21 10:12 mahnunchik

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).

phlummox avatar Jul 13 '23 14:07 phlummox

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.)

BorisAnthony avatar Jul 16 '23 13:07 BorisAnthony

I have no idea - as I said, it's undocumented. Or was your question directed at the eleventy maintainers?

phlummox avatar Jul 17 '23 09:07 phlummox

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/

zachleat avatar Dec 12 '23 18:12 zachleat

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 ..

zachleat avatar Dec 12 '23 23:12 zachleat

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 👍!

zachleat avatar Jun 19 '24 15:06 zachleat