Liquid/Jekyll:当一个人有两种或两种以上的情况时,如何检查没有帖子?

Liquid/Jekyll:当一个人有两种或两种以上的情况时,如何检查没有帖子?,jekyll,liquid,Jekyll,Liquid,我很难理解如何为带有两个变量的特定条件语句显示“不存在posts”消息 在这个例子中,假设我有一个“动物”的集合——在一个特定的页面上,我想要一个显示“草食性灵长类”的部分: 我想做的是这样的事情(伪代码): 注意:这与下面的示例不同,因为我有两个参数要检查。有人能提供一个关于语法的建议吗?我想你可以做以下的事情,首先从site.animal中通过物种=灵长类进行过滤,然后从该池中通过类型=食草动物进行过滤,然后检查结果是否存在 {% assign animals = site.animal |

我很难理解如何为带有两个变量的特定条件语句显示“不存在posts”消息

在这个例子中,假设我有一个“动物”的集合——在一个特定的页面上,我想要一个显示“草食性灵长类”的部分:

我想做的是这样的事情(伪代码):


注意:这与下面的示例不同,因为我有两个参数要检查。有人能提供一个关于语法的建议吗?

我想你可以做以下的事情,首先从
site.animal
中通过
物种=灵长类
进行过滤,然后从该池中通过
类型=食草动物
进行过滤,然后检查结果是否存在

{% assign animals = site.animal | where:"species","primate" | where:"type","herbivore" %}

{% if animals %}
  {% for animal in animals %}
    {{ animal.content }}
  {% endfor %}
{% endif %}
希望这有帮助

{% if POSTS_EXIST_FOR_THIS_COMBO: (animal.species == "primate" and animal.type == "herbivore") %}
      {% for animal in site.animal %}
        {% if animal.species == "primate" and animal.type == "herbivore" %}
          {{ animal.content }}
        {% endif %}
      {% endfor %}
{% else %}
     There are no posts for this category.
{% endif %}
{% assign animals = site.animal | where:"species","primate" | where:"type","herbivore" %}

{% if animals %}
  {% for animal in animals %}
    {{ animal.content }}
  {% endfor %}
{% endif %}