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

Layouts not working in 3.0? #3203

Closed
sfat-llc opened this issue Feb 18, 2024 · 6 comments
Closed

Layouts not working in 3.0? #3203

sfat-llc opened this issue Feb 18, 2024 · 6 comments

Comments

@sfat-llc
Copy link

Operating system

Windows 11

Eleventy

3.0.0_alpha5

Describe the bug

[11ty] Problem writing Eleventy templates: (more in DEBUG output)
[11ty] TemplateLayoutPathResolver directory does not exist for home: _includes (via Error)
[11ty]
[11ty] Original error stack trace: Error: TemplateLayoutPathResolver directory does not exist for home: _includes
[11ty]     at TemplateLayoutPathResolver.findFileName (file:///Y:/sfat.11ty.3/node_modules/@11ty/eleventy/src/TemplateLayoutPathResolver.js:105:10)
[11ty]     at TemplateLayoutPathResolver.init (file:///Y:/sfat.11ty.3/node_modules/@11ty/eleventy/src/TemplateLayoutPathResolver.js:74:25)
[11ty]     at new TemplateLayoutPathResolver (file:///Y:/sfat.11ty.3/node_modules/@11ty/eleventy/src/TemplateLayoutPathResolver.js:21:8)
[11ty]     at new TemplateLayout (file:///Y:/sfat.11ty.3/node_modules/@11ty/eleventy/src/TemplateLayout.js:18:18)
[11ty]     at TemplateLayout.getTemplate (file:///Y:/sfat.11ty.3/node_modules/@11ty/eleventy/src/TemplateLayout.js:58:17)
[11ty]     at Template.getLayout (file:///Y:/sfat.11ty.3/node_modules/@11ty/eleventy/src/Template.js:149:25)
[11ty]     at Template.getData (file:///Y:/sfat.11ty.3/node_modules/@11ty/eleventy/src/Template.js:355:22)
[11ty]     at async TemplateMap.add (file:///Y:/sfat.11ty.3/node_modules/@11ty/eleventy/src/TemplateMap.js:67:14)
[11ty]     at async Promise.all (index 3)
[11ty]     at async TemplateWriter._createTemplateMap (file:///Y:/sfat.11ty.3/node_modules/@11ty/eleventy/src/TemplateWriter.js:326:3)
[11ty] Wrote 0 files in 0.11 seconds (v3.0.0-alpha.5)
ERROR: "build:eleventy" exited with 1.

I'm trying to run my 11ty site in 3.0 as-is, in CJS. I'm getting above error. Layouts folder is declared inside eleventyConfig without changes from 2.0.1:

...
// ------------------------------ Layouts aliases -----------------------------
  eleventyConfig.addLayoutAlias("base", "base.njk");
  eleventyConfig.addLayoutAlias("contact", "contact.njk");
  eleventyConfig.addLayoutAlias("error", "error.njk");
  eleventyConfig.addLayoutAlias("home", "home.njk");
  eleventyConfig.addLayoutAlias("portfolio", "portfolio.njk");
  eleventyConfig.addLayoutAlias("services", "services.njk");

// --------------------------------- Eleventy ---------------------------------
  return {
    dir: {
      input: "src",
      output: "dist",
      layouts: "_layouts",
    },
    markdownTemplateEngine: "njk",
    htmlTemplateEngine: "njk",
  };
};

Reproduction steps

No response

Expected behavior

No response

Reproduction URL

No response

Screenshots

No response

@AmitParekh1771
Copy link

Line no. 2 of your error log says that,

[11ty] TemplateLayoutPathResolver directory does not exist for home: _includes (via Error)

which means that it's trying to check the home layout in the _includes directory and not _layouts. The _include directory doesn't exist in your case so I believe the error thrown may be due to the usage of include somewhere in your template.

Can you please clarify that,

  • It is also throwing an error whenever you're trying to use other layouts and NOT just home.
  • If no, where and how are you using the home layout?

@sfat-llc
Copy link
Author

All layouts. In 2.0.1 layouts folder was declared in eleventy.js, as shown above:

return {
    dir: {
      input: "src",
      output: "dist",
      layouts: "_layouts",
    },

11ty 3 seems to ignore this setting whatsoever and is looking for layouts inside _includes folder. So, is it a bug or a new feautre?

@zachleat
Copy link
Member

zachleat commented Apr 8, 2024

includes folder defaults to _includes if you do not specify (in both 2.0 and 3.0). This folder is not required to be distinct but it is required to exist.

Practically speaking, you can use includes: false or includes: "" to set this to match the input directory.

https://www.11ty.dev/docs/config/#directory-for-includes

@zachleat
Copy link
Member

zachleat commented Apr 8, 2024

This is an automated message to let you know that a helpful response was posted to your issue and for the health of the repository issue tracker the issue will be closed. This is to help alleviate issues hanging open waiting for a response from the original poster.

If the response works to solve your problem—great! But if you’re still having problems, do not let the issue’s closing deter you if you have additional questions! Post another comment and we will reopen the issue. Thanks!

@zachleat zachleat closed this as completed Apr 8, 2024
@CPritch
Copy link

CPritch commented Sep 18, 2024

All layouts. In 2.0.1 layouts folder was declared in eleventy.js, as shown above:

return {
    dir: {
      input: "src",
      output: "dist",
      layouts: "_layouts",
    },

11ty 3 seems to ignore this setting whatsoever and is looking for layouts inside _includes folder. So, is it a bug or a new feautre?

To actually answer the question you're asking. Place your layouts directory inside your includes directory.
So in this case you should place _layouts in /_includes by default. This should make your config work for v3.

See docs here:

Layouts can include subdirectories: layout: "layouts/base.njk" maps to _includes/layouts/base.njk.

@zachleat
Copy link
Member

If you upgrade to 3.0.0-alpha.17 or newer you’ll get a better error message via #727.

@zachleat zachleat added this to the Eleventy 3.0.0 milestone Sep 18, 2024
@11ty 11ty locked as resolved and limited conversation to collaborators Sep 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants