1

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...
5
  • You have this tagged [jekyll]. Jekyll has a way to do this (the HTML is a "template" and the Markdown document is a "page". How does Jekyll not work for you? Commented Feb 26, 2018 at 18:04
  • I am trying to do that also using variables but no luck yet. I have created layout and in layout I want to use variables to display for example 3 different .md files but don't know how to use those variables. Commented Feb 26, 2018 at 18:44
  • Ah, that was not clear from you question. Please include more information so we can help you. Don't use a comment, but edit your question. Commented Feb 26, 2018 at 18:48
  • Okay I have edited question, hope its clear now. Commented Feb 26, 2018 at 18:57
  • Possible duplicate of How to render two files from a single markdown Commented Feb 27, 2018 at 1:29

2 Answers 2

2

As far as I know, it's not possible to "load" two different pages in a layout file.

Do the pages HAVE to have YAML front-matter?
If not, I have a different solution for you: use Jekyll's Includes.

The way how includes work is basically this:

  • You put some HTML files in the _includes folder, for example foo.html
  • You can include their content into another file like this: {% include foo.html %}

The only problem is that by default, includes are supposed to be HTML files. But it's possible to use a Markdown file as an include, and render the Markdown by using Liquid's markdownify filter.

Example:

dev.html

(regular page, not layout file)

---
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.md

(without front-matter)

page1 file content in markdown...

page2.md

(without front-matter)

page2 file content in markdown...
Sign up to request clarification or add additional context in comments.

Comments

0

I would do this:

---
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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.