简体   繁体   中英

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?

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM