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

content partials #2982

Open
mrtnmgs opened this issue Jul 6, 2023 · 3 comments
Open

content partials #2982

mrtnmgs opened this issue Jul 6, 2023 · 3 comments

Comments

@mrtnmgs
Copy link

mrtnmgs commented Jul 6, 2023

Is your feature request related to a problem? Please describe.

I often need to break the content of a page into several files in order to separate code and content. (If the content can only be injected in one place in the template, in many case this separation is not possible). As far as I understand all partials must live in the _includes directory. But it's awkward to have part of the content in one place and another part elsewhere:

src
├── _includes
│   ├── layout.njk
│   └── shapes-partials
│       ├── circle-specs.md
│       ├── circle-options.md
│       ├── triangle-specs.md
│       └── triangle-options.md
└── shapes
    ├── circle.md
    └── triangle.md

I tried creating the partials where the page lives:

src
├── _includes
│   └── layout.njk
└── shapes
    ├── circle.md
    ├── circle-specs.md
    ├── circle-options.md
    ├── triangle.md
    ├── triangle-specs.md
    └── triangle-options.md

When I do this, a page is created for each partial. Adding the partials to .eleventyignore is not a working solution as hot reloading doesn't work anymore. It seems like partials have to live in the _includes directory in order to be handled properly. I had the same issue whether I imported the partial file with include or renderFile.

The best I was able to come with is specifying a separate directory for the layouts in .eleventy.js and move the location of the includes directory closer to the content. But if I use partials in different locations on my site it will still be awkward.

Maybe I'm thinking about this the wrong way? Is there another way to have different pieces of content injected in different places in a template?

Describe the solution you'd like

I think the simplest fix would be to allow several directories for includes:

  return {
    dir: {
      includes: ["_includes", "./foo/_includes", "./bar/_includes"]
    }
  }
};```

Or maybe files starting with an underscore could be treated as partials regardless of where they are? (with option to deactivate the feature and/or to configure the prefix. Even though the only issue I can think of is when one needs a url starting with an underscore, but there's always the option to set `permalink`)

### Describe alternatives you've considered

_No response_

### Additional context

_No response_
@uncenter
Copy link
Contributor

uncenter commented Jul 7, 2023

You could add layout: false (or "layout": false in a directory data file) for each of the partials and then layout: mylayout.njk for the main page in the folder. I'm not sure how you would include the pages properly though, maybe with the render plugin?

@uncenter
Copy link
Contributor

uncenter commented Jul 7, 2023

I'd also like to say that I think you already opened a ticket on the Discord forum for this issue! You'll will definitely get faster and better answers on there instead of here - most issues on this repo don't actively get responses.

@mrtnmgs
Copy link
Author

mrtnmgs commented Jul 24, 2023

Ok so from what I gather there's no 11ty way to do this... layout: false sounds interesting I'll try that. And noted re: discord vs github issues. Thanks for taking the time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants