Number field condition in Views

Support MB Views Number field condition in ViewsResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #18729
    Trang NguyenTrang Nguyen
    Participant

    Hi, I have a Number field, I want to set 3 results that depend on the value of this field:

    {% if post.price == 0 %}
        <p>Free</p>
    {% elseif post.price > 0 %}
        <p>{{ post.price }}</p>
    {% else %}
        <p>No info</p>
    {% endif %}

    It works with the condition == 0 and > 0 but for the {% else %} (empty or > 0) it always show "Free" (the same to condition == 0).

    How do I fix this to show "No info" when the price is != 0 neither > 0?

    Thank you!

    #18736
    Long NguyenLong Nguyen
    Moderator

    Hi,

    Your code works great with a number > 0 or = 0 (same with empty value)

    If you want to set the negative number (last else condition), you can set min to the number as you want such as -100 or PHP_INT_MIN with PHP version >= 7.0 or step to any for the floating numbers.

    For further information, please follow the Number field documentation

    #18780
    Trang NguyenTrang Nguyen
    Participant

    Thank you, Long. It works.
    I was thinking '0' is different from 'empty' so in case I leave the field empty it will show 'No Info'.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.