【问题标题】:Does Liquid have a "does not contain" or "not in array" operator?Liquid 是否有“不包含”或“不在数组中”运算符?
【发布时间】:2015-08-29 14:10:24
【问题描述】:

从 Liquid 模板中的数组调用项目时,如何调用 does not containnot in array

【问题讨论】:

    标签: jekyll liquid


    【解决方案1】:

    unless 救援!

    创建一个 [A, B, C] 数组。

    {% assign input = "A,B,C" | split:"," %}
    

    unless 仅在不满足约束时打印。

    这不打印:

    {% unless input contains 'A' %}No A{% endunless %}
    

    这会打印“No Z”:

    {% unless input contains 'Z' %}No Z{% endunless %}
    

    【讨论】:

    • 我的问题是我不能这样做:{% if input contains 'A' and input does not contain 'Z' %}
    • 使用两个嵌套条件{% if input contains 'A' %}{% unless input contain 'Z' %}
    【解决方案2】:

    你可以这样做:

    {% if collection.tags contains 'tag' %}
    {% else %}
      do stuff!
    {% endif %}
    

    【讨论】:

      猜你喜欢
      • 2018-12-04
      • 2017-02-05
      • 2012-02-08
      • 2018-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-22
      • 1970-01-01
      相关资源
      最近更新 更多