Search code examples
jekyllliquidgithub-pages

How to reference a post's whole content (including layout) in Jekyll/Liquid


I am using Jekyll (3.0+) and I have my index.html:

---
layout: mylayout
---
<div>
  {{ site.posts[0].content }}
</div>

As you can see I am trying to display only the first post and _layouts/mylayout.html is:

<article itemtype="http://schema.org/BlogPosting">
  <header>
    <h1>{{ page.title }}</h1>
  </header>
  <div>
    {{ content }}
  </div>
</article>

The layout is not included

The problem is that I cannot see the wrapping structure of mylayout.html, I can see just the content markdown translation! So, I would have expected:

<article itemtype="http://schema.org/BlogPosting">
  <header>
    <h1>Page title</h1>
  </header>
  <div>
    <section>My post paragraph</section>
    <p>Hello, this is my post.</p>
  </div>
</article>

But I got this:

<div>
  <section>My post paragraph</section>
  <p>Hello, this is my post.</p>
</div>

How can I refer to the whole page?


Solution

  • Looks like I need to use output property:

    ---
    layout: mylayout
    ---
    <div>
      {{ site.posts[0].output }}
    </div>
    

    This will basically return the whole HTML including the template!