【问题标题】:liquid variables stop working when layout is defined定义布局时,液体变量停止工作
【发布时间】:2020-01-07 02:14:09
【问题描述】:

非常感谢看到这个的人!我认为这个问题很简单。这只是因为我想非常彻底/有据可查。我从jekyll documentation 中获取了以下示例代码并对其进行了编辑,以便我可以通过永久链接找到它:

---
food: Pizza
permalink: "/pizza"
---

<h1>{{ page.food }}</h1>

当我运行jekyll serve 时,变量按原样输出,但没有布局。当我尝试添加我写到页面的布局时,变量不再输出,如here 所示。

最后,我想写一个循环分类的存档页面,exactly like this code in the documentation

{% for category in site.categories %}
  <h3>{{ category[0] }}</h3>
  <ul>
    {% for post in category[1] %}
      <li><a href="{{ post.url }}">{{ post.title }}</a></li>
    {% endfor %}
  </ul>
{% endfor %}

但是,由于液体变量不起作用,如果不放入 _layouts 目录或手动将我的布局复制粘贴到存档页面,我将无法制作存档。

对不起,如果我是一个 jekyll 新手(我是),或者如果答案在某个地方的文档中并且我找不到它,但这是我的问题:

  1. 为什么会出现这种情况?是关于 jekyll 的工作原理还是我的布局导致了这种情况?

  2. 编写存档/纠正此错误的最佳做法是什么?

整个项目的github仓库是here

【问题讨论】:

    标签: html jekyll github-pages liquid jekyll-theme


    【解决方案1】:

    您似乎在尝试获取内容时使用了错误的液体标签。注入页面内容时,使用{{ content }} 而不是{{ page.content }}。您可以在the docs 中查看示例。

    查看您包含的 post_body.htmlbody.html,您只需要修复上述问题,它应该可以工作。

    【讨论】:

      猜你喜欢
      • 2011-06-12
      • 2014-02-18
      • 2010-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-19
      • 1970-01-01
      • 2016-12-22
      相关资源
      最近更新 更多