我有一个名为/patterns
在我的 Jekyll 网站中,其结构通常如下所示:
_includes
_layouts
_site
/patterns
index.html
我需要保留/patterns
外部目录_includes
出于多种原因,但主要是因为我需要将文件拉入/patterns
到 iframe 中以在模式库中显示)。
我想包含来自以下位置的文件/patterns
在我的 Jekyll 页面中,但是使用{% include /patterns/file.html %} doesn't work as it points to the
_包括folder. How would I go about including a file from a directory that isn't
_包括`?
您可以选择包含相对于当前的文件片段
文件 https://jekyllrb.com/docs/includes/#including-files-relative-to-another-file通过使用include_relative
为您的标签/patterns/file.html
对于目录结构,您有:
_includes
_layouts
_site
/patterns/file.html
index.html
在这种情况下,以下内容不起作用:
{% include /patterns/file.html %}
Use include_relative
as /pattern
是相对的 to index.html
as the current file
:
{% include_relative patterns/file.html %}
Note:
你不能使用include_relative
标记布局文件夹中的任何文件。您只能使用include_relative
在页面或帖子上。布局代码在页面/帖子渲染的上下文中执行,并且 include_relative 是相对于该页面或帖子计算的,不是来自布局本身 https://stackoverflow.com/questions/28617211/in-jekyll-how-does-include-relative-work-with-respect-to-layout-files.
在这种情况下你的代码index.html
应该:
---
layout: null
---
(put all code from _layouts/default.html)
{% include_relative patterns/file.html %}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)