-
-
Notifications
You must be signed in to change notification settings - Fork 495
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
Liquid template can't find include file with relative path #3502
Comments
I came up with a workaround. First, change the config:
Then change the include to
I'm not sure if we still need to define It occurs to me that the included CSS file doesn't need to be in the public directory anyways because it's included in the template. So it would make more sense for it to be in the _includes directory. |
I think @harttle might need to weigh in here. The following test case fails via import { Liquid } from "liquidjs";
let lib = new Liquid({
root: ["./_includes", "./content"]
});
let tmpl = await lib.parse(`{% include '../public/style.css' %}`, './_includes/base.liquid');
let html = await lib.render(tmpl);
console.log( html );
as a workaround this works (but, why?): let lib = new Liquid({
root: ["./_includes", "./content", "."]
}); What does |
At least, After reading through the code, I would guess, it is because Liquid's loader is responsible for determining which directories to consider. |
@zachleat Thanks for looping me in. @dave-kennedy has provided a good explanation. Accessing outside of root/partials/layouts is not allowed. A quick fix without changing the template files is to update this line (allows everything in root: ["./_includes", "./content", "."] |
Thank you @harttle! |
@zachleat I think it would be good if the base blog used an approach that would work with another template engine. Probably exclude the css from the public folder too. |
Operating system
Ubuntu 22.04
Eleventy
3.0.0
Describe the bug
(For context, I was trying to implement the new bundle stuff in v3.0, following the pattern established by eleventy-base-blog, but ran into problems when I tried to include the css file in my layout. The only difference is I'm using Liquid templates.)
My project looks like this:
I want to include public/style.css in _includes/base.liquid:
But it throws this error:
Here's my config:
I tried changing the include path to
../public/style.css
but no dice there. If I use a Nunjucks layout instead then everything works great, but I'd rather stick with Liquid.Reproduction steps
Expected behavior
I should be able to include a file outside the layouts directory in a Liquid template.
Reproduction URL
https://github.com/dave-kennedy/eleventy-test
Screenshots
No response
The text was updated successfully, but these errors were encountered: