如何与“或”运算符一起使用“ where”过滤器

时间:2019-04-12 23:40:06

标签: jekyll liquid

我正在创建一个Liquid模板,在其中查找给定元数据标签为“ valueA”或“ valueB”的集合中的文档。

我尝试了以下操作:

{% assign item = site.rn | where: "type", "typeA" OR "typeB" %}
{% assign item = site.rn | where: "type", "typeA" "typeB" %} 
{% assign item = site.rn | where: "type", "typeA" | where: "type", "typeB" %}

以上示例均未返回type = typeA的两个项目和type = typeB的两个项目。前两个仅返回type = typeA的项目。第三个不返回任何内容,因为没有type = typeA和type = typeB的项目。

1 个答案:

答案 0 :(得分:0)

编辑

似乎是binary operator in where_expwill not be supported before Jekyll 4

正如您在问题下的注释中所指出的那样,您可以遍历集合并根据if控件结构来提供数组。

{% assign items = "" | split:"" %}

{% for item in site.rn %}
  {% if item.type == 'typeA' or item.type == 'typeB' %}
    {% assign items = items | push: item %}
  {% endif %}
{% endfor %}

结束编辑

这将在Jekyll 4中起作用

您可以尝试使用jekyll专用的“ where_exp”液体过滤器(see documentation)。

{% assign item = site.rn | where: "item", "item.type == 'typeA' or item.type == 'typeB'" %}
相关问题