Jekyll index.html使用3种不同的_layouts

use*_*885 7 jekyll

我有3个不同的_layouts.

  • 后link.html
  • 后article.html
  • 后photo.html

我可以在index.html上显示我的所有帖子,但它们都具有相同的布局.我能以某种方式在同一页面上显示多个布局(index.html)吗?

kzh*_*kzh 19

页面只能有一个layout,但布局可以嵌套.

我有三个_layouts:

  • master.html
  • default.html中
  • post.html

master布局具有所有的基本结构,任何网页我想需要的.它看起来像这样:

<html>
  <head>
    <title>{{ page.title }}</title>
  </head>
  <body>
    {{ content }}
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

default对大多数不是博客文章的页面使用布局.我page在页面的YAML前端内容中广泛使用了一些变量.布局看起来像这样:

---
layout: master
---
<h1>
  {{ page.title }}
  {% if page.subtitle %}<small>{{ page.subtitle }}</small>{% endif %}
</h1>
{% if page.description %}<p>{{ page.description }}</p>{% endif %}
{{ content }}
Run Code Online (Sandbox Code Playgroud)

我使用页面post布局_posts.它看起来像这样:

---
layout: default
---
<p>Posted {{ page.date }}</p>
<ul>{% for tag in page.tags %}...{% endfor %}</ul>
{{ content }}
Run Code Online (Sandbox Code Playgroud)

我制作的每篇博文都使用了post布局,并且他们继承了所有三种布局.

如果你想获得可重复使用标记的片段,那么我建议使用 _includes.


Tom*_*son 2

一个页面只能有一种布局。您需要的是 _includes,您可以在要显示帖子的任何地方使用它。