【问题标题】:How to reference a post's whole content (including layout) in Jekyll/Liquid如何在 Jekyll/Liquid 中引用帖子的全部内容(包括布局)
【发布时间】:2016-03-23 13:29:26
【问题描述】:

我正在使用 Jekyll (3.0+),我有我的 index.html:

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

如您所见,我试图只显示第一篇文章,_layouts/mylayout.html 是:

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

不包括布局

问题是我看不到mylayout.html的包装结构,我只能看到内容降价翻译!所以,我本来期望:

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

但我得到了这个:

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

我怎样才能引用整个页面?

【问题讨论】:

    标签: jekyll liquid github-pages


    【解决方案1】:

    看来我需要使用output 属性:

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

    这基本上会返回整个 HTML,包括模板!

    【讨论】:

    • 不幸的是,因为帖子的布局(post.html)通常继承自通常包含 HTML 头部的 default.html 布局,页眉和页脚(以便为单个帖子生成有效的 HTML 页面),并且 index.html 页面的布局也继承自 default.html 布局,使用 post.output 将生成一个无效的 HTML 文件,其中包含两个 HTML 头、页眉、页脚 - 一个来自 index.html => default.html 布局,一个来自 post_html => default.html 布局。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-18
    • 2021-07-11
    • 2016-12-22
    相关资源
    最近更新 更多