8

3 つの異なる _layouts があります。

  • post-link.html
  • post-article.html
  • post-photo.html

すべての投稿を index.html に表示できますが、レイアウトはすべて同じです。どうにかして同じページ (index.html) に複数のレイアウトを表示できますか?

4

2 に答える 2

20

1 つのページに含めることができる は 1 つのみlayoutですが、レイアウトはネストできます。

私は3つ持っています_layouts

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

レイアウトには、master必要なページに必要な基本構造がすべて含まれています。次のようになります。

<html>
  <head>
    <title>{{ page.title }}</title>
  </head>
  <body>
    {{ content }}
  </body>
</html>

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

postページのレイアウトを使用し_postsます。次のようになります。

---
layout: default
---
<p>Posted {{ page.date }}</p>
<ul>{% for tag in page.tags %}...{% endfor %}</ul>
{{ content }}

私が作成するすべてのブログ投稿では、postレイアウトを使用し、3 つのレイアウトすべてを継承しています。

再利用可能なマークアップのスニペットが必要な場合は、 _includes.

于 2012-12-31T03:54:55.237 に答える
2

ページには 1 つのレイアウトのみを含めることができます。必要なのは _includes で、投稿が表示される場所ならどこでも使用できます。

于 2012-11-21T12:02:35.403 に答える