gpt4 book ai didi

html - 定义布局时液体变量停止工作

转载 作者:行者123 更新时间:2023-12-04 21:01:25 25 4
gpt4 key购买 nike

非常感谢看到这篇文章的任何人!我认为这个问题很简单。之所以这么长,是因为我想非常彻底/有据可查。我从 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 %}

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

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

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

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

整个项目的 github 存储库是 here

最佳答案

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

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

关于html - 定义布局时液体变量停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59621348/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com