Skip to content

How to have *.11tydata.js file define different data for its different sub-folders? #2997

Answered by pdehaan
BorisAnthony asked this question in Q&A
Discussion options

You must be logged in to vote

I think it's possible, but it's overly complex and I'd suggest just using nested directory data files since it is a lot clearer and requires significantly less code/workarounds:

content/studio/about/about.11tydata.js
content/studio/readings/readings.11tydata.js
content/studio/writing/writing.11tydata.js

In my src/content/content.11tydata.js file I had to use eleventyComputed and then try and infer the directory from the filePathStem, and then dynamically set the tags[], layout, and permalink:

module.exports = {
  eleventyComputed: {
    tags(data) {
      // This will dynamically create `tags[]` like `["content", "studio", "about"]`
      // (although see caveats about dynamically set ta…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@BorisAnthony
Comment options

@pdehaan
Comment options

Answer selected by BorisAnthony
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants