【问题标题】:Category Page in JekyllJekyll 中的分类页面
【发布时间】:2017-07-07 03:56:32
【问题描述】:

我有一个category.html 页面,该页面将循环浏览特定类别的帖子。

{% for post in site.categories.tech %}

我想显示的是来自index.html页面,当用户点击时

{{ post.categories }}

这是从显示所有帖子的循环中生成的。

{% for post in site.posts %}

我需要{{ post.categories }} 变量来替换categories.html 中的.tech 像这样

{% for category in site.categories.{{ post.categories }} %}

我不知道如何将变量从index.html 传递给categories.html

【问题讨论】:

    标签: html jekyll liquid


    【解决方案1】:

    站点类别是一个对象,其中每个键都是类别名称。所以

    {{ site.categories }}
    

    输出如下:

    {
      "Category name" => [#, #, #, #, #, #, #],
      "Another category name" => [#, #, #, #, #, #, #],
      ...
    }
    

    因此,方括号应该这样做。所以如果在你的 index.html 的前面你有

    ---
    categories: tech
    ---
    

    下面的代码将呈现您在技术类别下的所有帖子。

    {% for post in site.categories[post.categories] %}
      {{ post }}
    {% endfor %}
    

    当然,如果你在前面有多个类别,这将不起作用,但我不知道你的用例。

    【讨论】:

    • 如何传递从 index.html 中单击的变量。如果用户点击了技术,我如何将它传递给 categories.html 并将值放在 [post.categories]
    • 我不明白“点击变量”是什么意思。请在index.html 中发布您如何定义该变量的示例
    • Post.categories 将被传递到下一页。
    猜你喜欢
    • 1970-01-01
    • 2013-10-18
    • 2014-01-03
    • 2021-05-22
    • 2018-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多