在Jekyll中,include_relative如何处理布局文件?

时间:2015-02-19 21:25:24

标签: include jekyll relative-path

我的default.html文件夹中有一个名为layouts的文件。在default.html中,我想将include添加到test.html,这也位于我的布局文件夹中。

我在{% include_relative test.html }%文件中添加default.html以包含test.html。但是,当我这样做时,我收到一个错误

"Liquid Exception: Included file './test.html' not found in
projects/[projectnmae]/layouts/default.html"

我的layouts文件夹位于我的配置文件中指定的其他位置。如果include_relative在这里以特殊的方式运作而我没有抓住任何想法?

2 个答案:

答案 0 :(得分:4)

您不能将include_relative标记与layouts文件夹中的任何文件一起使用。您只能在页面或帖子上使用include_relative

答案 1 :(得分:3)

布局代码在页面/后期渲染的上下文中执行,include_relative是相对于此页面或帖子计算的,而不是从布局本身计算的。

在调试器中跟踪此错误表明include_relative尝试加载/home/user/www/test/_posts/test.html而不是/home/user/www/test/_layouts/test.html