Jekyll 如何将内容添加到多个位置

Jekyll How to add content to multiple location

如何在一个布局文件中创建多个{{content}}。像这样...

_layout > default.html

<html>
<body>
  <H2>summary</H2>
  <p>
    {{content:summary}}
  </p>
  <H2>detail</H2>
  <p>
    {{content:detail}}
  </p>
</body>
</html>

index.html

----
layout: default
----
content:summary
<b>show superhero</b>

content:detail
<b>Spiderman Batman Spiderman</b>

输出

<html>
<body>
  <H2>summary</H2>
  <p>
    <b>show superhero</b>
  </p>
  <H2>detail</H2>
  <p>
    <b>Spiderman Batman Spiderman</b>
  </p>
</body>
</html>

Jekyll 仅支持一个 内容区域。您仍然可以使用技巧来获得示例中的结果。

只需将摘要放入页面的 YAML 前端:

index.html

----
layout: default
summary: "This is the summary"
----

This is the content

...并将其显示在您的布局文件中,如下所示:

_layouts/default.html

<html>
<body>
  <H2>summary</H2>
  <p>
    {{ page.summary }}
  </p>
  <H2>detail</H2>
  <p>
    {{ content }}
  </p>
</body>
</html>

输出将如下所示:

<html>
<body>
  <H2>summary</H2>
  <p>
    This is the summary
  </p>
  <H2>detail</H2>
  <p>
    This is the content
  </p>
</body>
</html>