在Jekyll中,include_relative对于布局文件如何工作?

Tom*_*son 3 relative-path include jekyll

我有一个名为default.html我的layouts文件夹中。在中default.html,我想添加一个相include对于的相对对象test.html,它也在我的layouts文件夹中。

{% include_relative test.html }%default.html文件中添加include test.html。但是,当我这样做时,我得到一个错误,指出

"Liquid Exception: Included file './test.html' not found in
projects/[projectnmae]/layouts/default.html"
Run Code Online (Sandbox Code Playgroud)

我的layouts文件夹确实位于配置文件中指定的其他位置。有什么想法include_relative可以以一种我不掌握的特殊方式起作用吗?

Dav*_*uel 5

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

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


Tom*_*son 5

您不能对include_relative布局文件夹内的任何文件使用标记。您只能include_relative在页面或帖子上使用。