How to use multiple arguments in an if statement with Liquid

前端 未结 2 1340
滥情空心
滥情空心 2020-12-14 06:09

I want to use an if statement in Liquid with multiple conditionals. Something like:

{% if (include.featured == \"true\" and product.featured ==          


        
相关标签:
2条回答
  • 2020-12-14 06:38

    Unfortunately, Liquid has a poor implementation of boolean algebra.

    Using Liquid's operators and tags, here is a dirty way to achieve it:

    {% if include.featured == true and product.featured == true %}
          {% assign test = true %}
    {% endif %}
    
    {% if include.featured == false and product.featured == false %}
          {% assign test = true %}
    {% endif %}
    
    {% if test %}
          Yepeeee!
    {% endif %}
    
    0 讨论(0)
  • 2020-12-14 06:57

    Another way you can condense this is to combine else if statements, and booleans don't necessarily need the "==" when evaluating true:

    {% if include.featured and product.featured %}
          {% assign test = true %}
    {% elsif include.featured == false and product.featured == false %}
          {% assign test = false %}
    {% endif %}
    
    0 讨论(0)
提交回复
热议问题