In Jekyll, I have created a layout file dev.html
which is already using some other layout: default
but that is not important.
dev.html
---
layout: default
title: Developer
---
<div>
{{ want to include page1.md }}
</div>
<div>
{{ want to include page2.md }}
</div>
Now, I have those 2 markdown pages which I need to include somehow in dev.html file. How can I do that? I have tried using variable {{content}}
but that would include both pages at once in the dev.html
file.
page1.md
---
layout: dev
---
page1 file content in markdown...
page2.md
---
layout: dev
---
page2 file content in markdown...
答案 0 :(得分:0)
据我所知,不可能在布局文件中“加载”两个不同的页面。
页面是否必须具有YAML前置问题?
如果没有,我会为您提供不同的解决方案:使用Jekyll的Includes。
包括工作的方式基本上是这样的:
_includes
文件夹中,例如foo.html
{% include foo.html %}
唯一的问题是默认情况下,包含应该是HTML文件。但是可以使用Markdown文件作为包含,并使用Liquid的markdownify
过滤器渲染Markdown。
示例:
(常规页面,不是布局文件)
---
layout: default
title: Developer
---
<div>
{% capture p1 %}{% include page1.md %}{% endcapture %}
{{ p1 | markdownify }}
</div>
<div>
{% capture p2 %}{% include page2.md %}{% endcapture %}
{{ p2 | markdownify }}
</div>
(没有前面的内容)
page1 file content in markdown...
(没有前面的内容)
page2 file content in markdown...
答案 1 :(得分:0)
我会这样做:
---
layout: default
title: Developer
---
<div>
{% assign sitepages = site.pages | where: "slug", "page1" %}
{% for p in sitepages %}
{{ p.content }}
{% endfor %}
</div>
<div>
{% assign sitepages = site.pages | where: "slug", "page2" %}
{% for p in sitepages %}
{{ p.content }}
{% endfor %}
</div>