我根本无法在 Jekyll 中使用自定义前面的内容

问题描述 投票:0回答:1

我正在我的 Jekyll 网站中测试导航栏,但我在前面写的任何内容都无法显示在其中。 Jekyll 没有显示任何构建错误。

我有一个布局default.html,然后我将navigation.html包含在其中。 我的 navigation.html 看起来像这样:

<div>
    {% if site.data.samplelist.toc2[0] %}
      {% for item in site.data.samplelist.toc2 %}
        <h3>{{ item.title }}</h3>
          {% if item.subfolderitems[0] %}
            <ul>
              {% for entry in item.subfolderitems %}
                  <li><a href="{{ entry.url }}">{{ entry.page }}</a>
                    {% if entry.subsubfolderitems[0] %}
                      <ul>
                      {% for subentry in entry.subsubfolderitems %}
                          <li><a href="{{ subentry.url }}">{{ subentry.page }}</a></li>
                      {% endfor %}
                      </ul>
                    {% endif %}
                  </li>
              {% endfor %}
            </ul>
          {% endif %}
        {% endfor %}
    {% endif %}
</div>

这是我正在测试的页面的正面内容:

---
layout: docs
title: "The Difference between は and が"
toc2:
  - title: Group 1
    subfolderitems:
      - page: Thing 1
        url: /thing1.html
      - page: Thing 2
        url: /thing2.html
        subsubfolderitems:
          - page: Subthing 1
            url: /subthing1.html
          - page: Subthing 2
            url: /subthing2.html
      - page: Thing 3
        url: /thing3.html
  - title: Group 2
    subfolderitems:
      - page: Piece 1
        url: /piece1.html
      - page: Piece 2
        url: /piece2.html
      - page: Piece 3
        url: /piece3.html
        subsubfolderitems:
          - page: Subpiece 1
            url: /subpiece1.html
          - page: Subpiece2
            url: /subpiece2.html
  - title: Group 3
    subfolderitems:
      - page: Widget 1
        url: /widget1.html
        subsubfolderitems:
          - page: Subwidget 1
            url: /subwidget1.html
          - page: Subwidget 2
            url: /subwidget2.html
      - page: Widget 2
        url: /widget2.html
      - page: Widget 3
        url: /widget3.html
---

前面的内容是 来自 Jekyll 文档网站的示例。但在我构建之后,导航 div 中没有显示任何内容。

即使我做了一些简单的事情,比如在我的前面有

food: Pizza
,然后在我的默认布局上有
<h1>{{ page.food }}</h1>
,也不会返回任何内容。如果我直接将
<h1>{{ page.food }}</h1>
粘贴到 .md 页面上并使用自定义前面的内容,它只会返回一些内容。

yaml frontend jekyll yaml-front-matter
1个回答
0
投票

我发现我应该将 YAML 放在我的 _data 文件夹中(在本例中,位于 Samplelist.yml 下)。这使得 Liquid 返回正确的值。我链接的 Jekyll 文档页面中的场景 8 似乎是唯一适用于各个页面中的前面内容的场景。

© www.soinside.com 2019 - 2024. All rights reserved.