In Jekyll, how does include_relative work with respect to layout files?

妖精的绣舞 提交于 2019-12-23 19:57:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!