高架:仅在博客文章中添加分页

发布于 2025-01-23 02:37:52 字数 415 浏览 5 评论 0原文

在高度中,我有一个简单的布局文件,我想在网站上的大多数页面(包括博客集合)中使用该文件。我希望在博客文章中仅添加我的分页部分。

我以下尝试并未将分页添加到任何帖子中。我知道我需要修改if语句,但我不知道如何。如果我不包含if语句,一切正常,但是不在博客集合中的页面从部分中获得一些代码,我不想要。

有什么建议吗?

---
layout: layouts/base.njk
---
<article>
  <h1>{{ title }}</h1>
  {{ content | safe }}
</article>
{% if post in collections.blog %}
  {% include "partials/_pagination.njk" %}
{% endif %}

In Eleventy, I have a simple layout file that I'd like to use for most pages on my website, including the blog collection. I'd like the layout to only add my pagination partial when in a blog post.

My attempt below doesn't add the pagination partial to any post. I know I need to modify the if statement, but I don't know how. Everything works fine if I don't include the if statement, but pages not in the blog collection get some of the code from partial, which I don't want.

Any suggestions?

---
layout: layouts/base.njk
---
<article>
  <h1>{{ title }}</h1>
  {{ content | safe }}
</article>
{% if post in collections.blog %}
  {% include "partials/_pagination.njk" %}
{% endif %}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蹲在坟头点根烟 2025-01-30 02:37:52

我得到了高度不和谐小组的答案:

---
layout: layouts/base.njk
---
<article>
  <h1>{{ title }}</h1>
  {{ content | safe }}
</article>
{% if "blog" in tags %}
  {% include "partials/_pagination.njk" %}
{% endif %}

I got the answer from the Eleventy group on Discord:

---
layout: layouts/base.njk
---
<article>
  <h1>{{ title }}</h1>
  {{ content | safe }}
</article>
{% if "blog" in tags %}
  {% include "partials/_pagination.njk" %}
{% endif %}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文