2016-09-27 33 views
9

之外我在杰奇的网站叫/patterns一个目录,其结构通常一般是这样的:杰基尔:包括从目录中的文件_includes

_includes _layouts _site /patterns index.html

我需要保持/patterns目录外_includes原因很多,但主要是因为我需要将/patterns中的文件放入iframe中以显示在模式库中)。

我想在我的Jekyll页面中包含来自/patterns的文件,但使用{% include /patterns/file.html %} doesn't work as it points to the _includes folder. How would I go about including a file from a directory that isn't _includes`?

回答

2

在你_config.yml,您可以添加额外的目录,像这样:

includes: 
- patterns 

就像这么简单!

在这里的行动在我的杰奇网站:https://github.com/pschfr/pschfr.github.io/blob/master/_config.yml

+1

太棒了!如果我设置了这个选项,'/ patterns'仍然会编译并显示在'/ _site'中? –

+0

如果你在'/ patterns'中放置了一个index.html,我相信! – Paul

+0

嗯,这是当我将我的建议添加到我的'_config.yml'时:'LiquidException:包含的文件'_includes/patterns/file-name.html'not found'。 要清楚,我试图包含这样的文件:'{%include /patterns/file-name.html%}'也许我做错了吗? –

1

我认为collections会做你的需要。它们可以包含并呈现为公共html。

这是一个example project这样做。

+0

谢谢!我可能会误解,但我认为用'_'作为前缀的目录意味着在编译时,Jekyll不会在'_site'中包含该目录。对于我的用例,我需要在'/ _site'中包含'/ patterns',因为我在iframe中引用了这些文件。 –

+1

通常对于下划线是正确的,但是集合有一个特别的选项来写出可公开访问的html。我鼓励你下载示例项目并运行'jekyll build'来看看它是如何工作的。 –

+1

另外,如果你打开index.html文件,你可以看到如何将它包含在液体和iframe中。 –

3

您可以在_config.yml中更改include标签使用的目录includes_dir。它看起来不像可以设置多个路径(来源:https://jekyllrb.com/docs/configuration/)。

在任何情况下,_includes中的文件都不会输出。您可以将特定于模式的内容分为_includes/patterns/,但唯一对您的实际站点有影响的内容是包含这些文件的位置。

0

我把一个符号链接代替指向我想要的_includes目录,因为includes_dir似乎不喜欢../指定一个相对路径(一个或多个目录更高)。