问题
I have a file called default.html in my layouts folder. In default.html, I want to add a relative include to test.html, which is also in my layouts folder.
I add {% include_relative test.html }% in my default.html file to include test.html. However, when I do this, I get an error that says
"Liquid Exception: Included file './test.html' not found in
projects/[projectnmae]/layouts/default.html"
I do have my layouts folder in a different location, as specified in my configuration file. Any ideas if include_relative works in a special way here that I'm not grasping?
回答1:
You can't use the include_relative tag with any files inside your layouts folder. You can only use include_relative on a page or post.
回答2:
Layouts code is executed in the context of page/post rendering and the include_relative is calculated relative to this page or post, not from the layout itself.
Tracking this error in debugger shows that include_relative tries to load /home/user/www/test/_posts/test.html and not /home/user/www/test/_layouts/test.html
来源:https://stackoverflow.com/questions/28617211/in-jekyll-how-does-include-relative-work-with-respect-to-layout-files