在Jekyll配置文件(站点导航)中苦苦寻找数组

5 yaml jekyll

在我的_config.yml身上:

navigation:
- text: Home
  url: index.html
- text: About
  url: about.html
- text: Blog
  url: blog.html
- text: Portfolio
  url: portfolio.html
Run Code Online (Sandbox Code Playgroud)

在我的default.html布局中,我有:

<ul class="nav-list">
  {% for link in site.navigation %}
    {% assign current = nil %}
    {% if page.url == link.url %}
      {% assign current = 'current' %}
    {% endif %}

    <li class="nav-list-item{% if forloop.first %}first{% endif %} {{ current }} {% if forloop.last %}nav-list-item-last{% endif %}">
      <a class="{{ current }}" href="{{ link.url }}">{{ link.text }}</a>
    </li>
  {% endfor %}
</ul>
Run Code Online (Sandbox Code Playgroud)

出于某种原因,这是行不通的.为什么会这样?

Tho*_*ggi 4

我刚刚发现你必须重新启动服务器并jekyll --server再次运行,_config.yml变量才可以访问。

然后在弄清楚之后回到这个页面并准备发布这个答案,点击add / show 4 more comments并看到这也被操作员发现了。因此将其发布为答案。